Given the reduced example below I receive a really long and misleading exception instead of a short descriptive error:
```import javax.inject.Inject;
import javax.inject.Provider;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
public class Main {
public static void main(String[] args) throws Exception {
Injector injector = Guice.createInjector(Stage.DEVELOPMENT, new AbstractModule() {
@Override
protected void configure() {}
});
injector.getInstance(Outer.class);
}
}
abstract class Abstract {
@Inject
public Abstract(Outer o) {}
}
class Middle {
@Inject
public Middle(Outer o, Provider
}
class Middle2 {
@Inject
public Middle2(Outer o) {}
}
class Outer {
@Inject
public Outer(Provider
System.out.println("SUCCESS!");
}
}
The error message I get is:
Exception in thread "main" com.google.common.util.concurrent.UncheckedExecutionException: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: Recursive load of: Outer.
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2047)
at com.google.common.cache.LocalCache.get(LocalCache.java:3869)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3873)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4798)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4804)
at com.google.inject.internal.FailableCache.get(FailableCache.java:51)
at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:48)
at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:154)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:595)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:932)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:852)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:291)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:222)
at com.google.inject.internal.InjectorImpl.getProviderOrThrow(InjectorImpl.java:1040)
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1071)
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1034)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1086)
at Main.main(Main.java:17)
Caused by: com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: Recursive load of: Outer.
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2047)
at com.google.common.cache.LocalCache.get(LocalCache.java:3869)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3873)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4798)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4804)
at com.google.inject.internal.FailableCache.get(FailableCache.java:51)
at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:48)
at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:154)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:595)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:932)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:852)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:291)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:222)
at com.google.inject.internal.InjectorImpl.createProviderBinding(InjectorImpl.java:358)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:891)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:852)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:291)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:222)
at com.google.inject.internal.InjectorImpl.createParameterInjector(InjectorImpl.java:990)
at com.google.inject.internal.InjectorImpl.getParametersInjectors(InjectorImpl.java:978)
at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:68)
at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:29)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:37)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:33)
at com.google.inject.internal.FailableCache$1.load(FailableCache.java:40)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3443)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2169)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2128)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2041)
... 17 more
Caused by: java.lang.IllegalStateException: Recursive load of: Outer.
at com.google.common.base.Preconditions.checkState(Preconditions.java:585)
at com.google.common.cache.LocalCache$Segment.waitForLoadingValue(LocalCache.java:2145)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2135)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2041)
at com.google.common.cache.LocalCache.get(LocalCache.java:3869)
at com.google.common.cache.LocalCache.getOrLoad(LocalCache.java:3873)
at com.google.common.cache.LocalCache$LocalLoadingCache.get(LocalCache.java:4798)
at com.google.common.cache.LocalCache$LocalLoadingCache.getUnchecked(LocalCache.java:4804)
at com.google.inject.internal.FailableCache.get(FailableCache.java:51)
at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:48)
at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:154)
at com.google.inject.internal.InjectorImpl.initializeJitBinding(InjectorImpl.java:595)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:932)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:852)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:291)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:222)
at com.google.inject.internal.InjectorImpl.createParameterInjector(InjectorImpl.java:990)
at com.google.inject.internal.InjectorImpl.getParametersInjectors(InjectorImpl.java:978)
at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:68)
at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:29)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:37)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:33)
at com.google.inject.internal.FailableCache$1.load(FailableCache.java:40)
at com.google.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3443)
at com.google.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2169)
at com.google.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2128)
at com.google.common.cache.LocalCache$Segment.get(LocalCache.java:2041)
... 45 more
Instead of an error message like (if Outer m2 is removed):
Exception in thread "main" com.google.inject.ConfigurationException: Guice configuration errors:
1) No implementation for Abstract was bound.
while locating com.google.inject.Provider
for the 2nd parameter of Middle.
while locating com.google.inject.Provider
for the 1st parameter of Outer.
while locating Outer
1 error
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1075)
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1034)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1086)
at Main.main(Main.java:17)
``
I'm using
com.google.inject:guice:4.2.0`
Had the a similar problem. We have a fairly complex dependency graph so this makes debugging very, very difficult. After trying a lot of different things "fixed" it by injecting a suspect dependency as a provider, then I got the helpful error message and was able to fix the real issue so there's definitively a bug in this area.
I somehow get a very similar com.google.common.util.concurrent.UncheckedExecutionException
as well and it turns out if I use Guice version 4.2.2
then it is showing me the real issue, instead of this mystery error. Then I can solve it by solving the real issue. I guess you can perhaps test out the new version as well?
Thank you @liufuyang your comment saved my day
Sounds like this has been fixed as of 4.2.2 then?
@dimo414 Is 4.4.2
a public release? Or do you mean 4.2.2
?
@adrw yep that's what I meant, was referring to this comment suggesting the issue is resolved.