You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using nested Guice injectors, the exception message makes it look like any error in the inner injector is occurring in the outer injector.
Example 1
In this code, each test attempts to create a Guice injector that cannot be created.
createNonNestedModule creates a Guice injector with a missing dependency
createNestedModule creates a Guice injector whose only module ModuleWithNestedGuiceInjector throws when created. This module ModuleWithNestedGuiceInjector throws because it creates a nested Guice injector with a missing dependency.
These two failures are from two fundamentally different Guice injectors failing to start up (i.e. the nested injector, or the outer injector), however the exception message does not allow them to be distinguished.
Unable to create injector, see the following errors:
1) [Guice/MissingImplementation]: No implementation for DemoTest$MyInterface was bound.
Requested by:
1 : DemoTest$MyClass.<init>(DemoTest.java:23)
\_ for 1st parameter myInterface
at DemoTest$MyModule.configure(DemoTest.java:15)
Learn more:
https://github.com/google/guice/wiki/MISSING_IMPLEMENTATION
1 error
======================
Full classname legend:
======================
DemoTest$MyClass: "com.example.DemoTest$MyClass"
DemoTest$MyInterface: "com.example.DemoTest$MyInterface"
DemoTest$MyModule: "com.example.DemoTest$MyModule"
========================
End of classname legend:
========================
com.google.inject.CreationException: Unable to create injector, see the following errors:
1) [Guice/MissingImplementation]: No implementation for DemoTest$MyInterface was bound.
Requested by:
1 : DemoTest$MyClass.<init>(DemoTest.java:23)
\_ for 1st parameter myInterface
at DemoTest$MyModule.configure(DemoTest.java:15)
Learn more:
https://github.com/google/guice/wiki/MISSING_IMPLEMENTATION
1 error
======================
Full classname legend:
======================
DemoTest$MyClass: "com.example.DemoTest$MyClass"
DemoTest$MyInterface: "com.example.DemoTest$MyInterface"
DemoTest$MyModule: "com.example.DemoTest$MyModule"
========================
End of classname legend:
========================
at app//com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:576)
at app//com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:163)
at app//com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at app//com.google.inject.Guice.createInjector(Guice.java:87)
at app//com.google.inject.Guice.createInjector(Guice.java:69)
at app//com.google.inject.Guice.createInjector(Guice.java:59)
at app//com.example.DemoTest.createNonNestedModule(DemoTest.java:37)
at java.base@17.0.8/java.lang.reflect.Method.invoke(Method.java:568)
at java.base@17.0.8/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base@17.0.8/java.util.ArrayList.forEach(ArrayList.java:1511)
Nested exception message
Unable to create injector, see the following errors:
1) [Guice/MissingImplementation]: No implementation for DemoTest$MyInterface was bound.
Requested by:
1 : DemoTest$MyClass.<init>(DemoTest.java:23)
\_ for 1st parameter myInterface
at DemoTest$MyModule.configure(DemoTest.java:15)
Learn more:
https://github.com/google/guice/wiki/MISSING_IMPLEMENTATION
1 error
======================
Full classname legend:
======================
DemoTest$MyClass: "com.example.DemoTest$MyClass"
DemoTest$MyInterface: "com.example.DemoTest$MyInterface"
DemoTest$MyModule: "com.example.DemoTest$MyModule"
========================
End of classname legend:
========================
com.google.inject.CreationException: Unable to create injector, see the following errors:
1) [Guice/MissingImplementation]: No implementation for DemoTest$MyInterface was bound.
Requested by:
1 : DemoTest$MyClass.<init>(DemoTest.java:23)
\_ for 1st parameter myInterface
at DemoTest$MyModule.configure(DemoTest.java:15)
Learn more:
https://github.com/google/guice/wiki/MISSING_IMPLEMENTATION
1 error
======================
Full classname legend:
======================
DemoTest$MyClass: "com.example.DemoTest$MyClass"
DemoTest$MyInterface: "com.example.DemoTest$MyInterface"
DemoTest$MyModule: "com.example.DemoTest$MyModule"
========================
End of classname legend:
========================
at app//com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:576)
at app//com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:163)
at app//com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at app//com.google.inject.Guice.createInjector(Guice.java:87)
at app//com.google.inject.Guice.createInjector(Guice.java:69)
at app//com.google.inject.Guice.createInjector(Guice.java:59)
at app//com.example.DemoTest.createNestedModule(DemoTest.java:42)
at java.base@17.0.8/java.lang.reflect.Method.invoke(Method.java:568)
at java.base@17.0.8/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base@17.0.8/java.util.ArrayList.forEach(ArrayList.java:1511)
Example 2
The second example shows why this is confusing in practice. The exception message does not allow the user to work out which injector has the missing dependency. The exception messages for these two test are the same (apart from the test method in the stack trace).
Unable to create injector, see the following errors:
1) [Guice/MissingImplementation]: No implementation for DemoTest$MyInterface was bound.
Requested by:
1 : DemoTest$MyClass.<init>(DemoTest.java:31)
\_ for 1st parameter myInterface
at DemoTest$MyModule.configure(DemoTest.java:22)
Learn more:
https://github.com/google/guice/wiki/MISSING_IMPLEMENTATION
1 error
======================
Full classname legend:
======================
DemoTest$MyClass: "com.example.DemoTest$MyClass"
DemoTest$MyInterface: "com.example.DemoTest$MyInterface"
DemoTest$MyModule: "com.example.DemoTest$MyModule"
========================
End of classname legend:
========================
com.google.inject.CreationException: Unable to create injector, see the following errors:
1) [Guice/MissingImplementation]: No implementation for DemoTest$MyInterface was bound.
Requested by:
1 : DemoTest$MyClass.<init>(DemoTest.java:31)
\_ for 1st parameter myInterface
at DemoTest$MyModule.configure(DemoTest.java:22)
Learn more:
https://github.com/google/guice/wiki/MISSING_IMPLEMENTATION
1 error
======================
Full classname legend:
======================
DemoTest$MyClass: "com.example.DemoTest$MyClass"
DemoTest$MyInterface: "com.example.DemoTest$MyInterface"
DemoTest$MyModule: "com.example.DemoTest$MyModule"
========================
End of classname legend:
========================
at app//com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:576)
at app//com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:163)
at app//com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:110)
at app//com.google.inject.Guice.createInjector(Guice.java:87)
at app//com.google.inject.Guice.createInjector(Guice.java:69)
at app//com.google.inject.Guice.createInjector(Guice.java:59)
at app//com.example.DemoTest.createNonNestedModule(DemoTest.java:41)
at java.base@17.0.8/java.lang.reflect.Method.invoke(Method.java:568)
at java.base@17.0.8/java.util.ArrayList.forEach(ArrayList.java:1511)
at java.base@17.0.8/java.util.ArrayList.forEach(ArrayList.java:1511)
Other notes
I've tested the above examples in Guice 6.0.0 and 7.0.0.
The text was updated successfully, but these errors were encountered:
When using nested Guice injectors, the exception message makes it look like any error in the inner injector is occurring in the outer injector.
Example 1
In this code, each test attempts to create a Guice injector that cannot be created.
createNonNestedModule
creates a Guice injector with a missing dependencycreateNestedModule
creates a Guice injector whose only moduleModuleWithNestedGuiceInjector
throws when created. This moduleModuleWithNestedGuiceInjector
throws because it creates a nested Guice injector with a missing dependency.These two failures are from two fundamentally different Guice injectors failing to start up (i.e. the nested injector, or the outer injector), however the exception message does not allow them to be distinguished.
Non-nested exception message
Nested exception message
Example 2
The second example shows why this is confusing in practice. The exception message does not allow the user to work out which injector has the missing dependency. The exception messages for these two test are the same (apart from the test method in the stack trace).
Exception message
Other notes
The text was updated successfully, but these errors were encountered: