IllegalStateException instead of understandable error message like "No implementation for Abstract was bound"
See original GitHub issueGiven the reduced example below I receive a really long and misleading exception instead of a short descriptive error:
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<Abstract> a) {}
}
class Middle2 {
@Inject
public Middle2(Outer o) {}
}
class Outer {
@Inject
public Outer(Provider<Middle> m, Provider<Middle2> m2) { // remove m2 to get the good error message
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.<init>()
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.<init>()
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.<init>()
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<Abstract>
for the 2nd parameter of Middle.<init>(Main.java:30)
while locating com.google.inject.Provider<Middle>
for the 1st parameter of Outer.<init>(Main.java:42)
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
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Google Guice configuration error (No implementation was ...
It seems your module registering dependencies is missing. You need to tell Guice what class will be used when it is asked for...
Read more >KT-36770 - YouTrack - JetBrains
This is just an implementation bug caused by a combination of two factors: a very special Java type @NotNull V that is not...
Read more >How to Solve java.lang.IllegalStateException in Java main ...
This exception is rise explicitly by programmer or by the API developer to indicate that a method has been invoked at the wrong...
Read more >Component Tests (with Guice) - OpenDaylight Documentation
A component test based on Guice wiring, such as AclServiceTest, will now fail on you with a message saying something like this: No...
Read more >Stop using Page Objects and Start using App Actions - Cypress
Instead of ad-hoc interactions with a page, a test controls the page ... After adding a custom command, the tests can use it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@adrw yep that’s what I meant, was referring to this comment suggesting the issue is resolved.
Thank you @liufuyang your comment saved my day