Skip to content

Commit

Permalink
Merge pull request #413 from carl-mastrangelo/nocircles
Browse files Browse the repository at this point in the history
Avoid referring to internal Guice classes
  • Loading branch information
asibross authored Apr 19, 2021
2 parents 96d3f38 + da7f0b6 commit edfcccc
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import com.google.inject.Key;
import com.google.inject.Provider;
import com.google.inject.ProvisionException;
import com.google.inject.internal.CircularDependencyProxy;
import com.netflix.governator.internal.AbstractScope;

import java.util.Map;
Expand All @@ -35,6 +34,19 @@ class FineGrainedLazySingletonScopeImpl extends AbstractScope
private static final Object NULL = new Object();
private static final Map<Key<?>, LockRecord> locks = Maps.newHashMap();

private static final Class<?> circularProxyClazz;

static {
Class<?> clz;
try {
clz = Class.forName("com.google.inject.internal.CircularDependencyProxy");
} catch (ClassNotFoundException e) {
clz = null;
// discard exception.
}
circularProxyClazz = clz;
}

private static class LockRecord
{
private final Object lock = new Object();
Expand Down Expand Up @@ -68,7 +80,8 @@ public T get()
T provided = creator.get();

// don't remember proxies; these exist only to serve circular dependencies
if ( provided instanceof CircularDependencyProxy )
// Don't do an instanceof check to avoid referencing Guice internal classes.
if (circularProxyClazz != null && circularProxyClazz.isInstance(provided))
{
return provided;
}
Expand Down

0 comments on commit edfcccc

Please sign in to comment.