Comments (8)
Thanks for this. I'll add a test case and fix this regression.
On Mon, Oct 20, 2014, 08:40 Colin Alworth [email protected] wrote:
In attempting to use a circular dependency (with Lazy, as appears to be
possible in dagger1), I found a case where a StackOverflowError occurs when
attempting to report the cycle to the user.This example is striped down as much as possible - removing or simplifying
any further appears to make this bug go away.public class LazyCycleBroken {
@Component public static interface MyComponent { App app(); } public static class App { @Inject Bar bar; @Inject public App() { } } public static class Bar { @Inject Lazy<Foo> lazyFoo;//in dagger1 this is legal, in dagger2 cycles of any kind are forbidden @Inject public Bar() { } } public static class Foo { @Inject Bar bar; @Inject public Foo() { } }
}
Useful part of the stack trace:
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:238)
at dagger.internal.codegen.BindingGraphValidator.reportCycle(BindingGraphValidator.java:195)
at dagger.internal.codegen.BindingGraphValidator.access$300(BindingGraphValidator.java:34)
at dagger.internal.codegen.BindingGraphValidator$1.visitResolvedBinding(BindingGraphValidator.java:72)
at dagger.internal.codegen.BindingGraphValidator.traversalHelper(BindingGraphValidator.java:234)
at dagger.internal.codegen.BindingGraphValidator.validate(BindingGraphValidator.java:54)
at dagger.internal.codegen.ComponentProcessingStep.process(ComponentProcessingStep.java:71)—
Reply to this email directly or view it on GitHub
#45.
from dagger.
Circular deps are now errors.
from dagger.
Is it included in dagger-2.0-20141117.023126-9.jar build? I'm getting an almost identical stacktrace.
from dagger.
Not yet fixed.
On Tue Nov 18 2014 at 10:51:32 AM Serandel [email protected] wrote:
Is it included in dagger-2.0-20141117.023126-9.jar build? I'm getting an
almost identical stacktrace.—
Reply to this email directly or view it on GitHub
#45 (comment).
from dagger.
This fixed yet?
from dagger.
@gk5885 @cgruber I stumbled on a Devoxx video where you (@cgruber) said Dagger is “JSR 330 compliant”, and for some reason it reminded me that I had once tried to test Dagger 1 against the AtInject TCK (modified to disable checks for known deviations from the spec), and I hadn't seen Dagger 2 tested against the TCK.
Adding the TCK in an integration-test was easy, but it doesn't compile because of a circular dependency (through Provider
):
[INFO] [WARNING] Generating a MembersInjector or Factory for org.atinject.tck.auto.Convertible. Prefer to run the dagger processor over that class instead.
[INFO] [WARNING] Generating a MembersInjector or Factory for org.atinject.tck.auto.Convertible. Prefer to run the dagger processor over that class instead.
[INFO] [WARNING] Generating a MembersInjector or Factory for org.atinject.tck.auto.DriversSeat. Prefer to run the dagger processor over that class instead.
[INFO] [WARNING] Generating a MembersInjector or Factory for org.atinject.tck.auto.accessories.Cupholder. Prefer to run the dagger processor over that class instead.
[INFO] [WARNING] Generating a MembersInjector or Factory for org.atinject.tck.auto.Seat. Prefer to run the dagger processor over that class instead.
[INFO] [WARNING] Generating a MembersInjector or Factory for org.atinject.tck.auto.accessories.SpareTire. Prefer to run the dagger processor over that class instead.
[INFO] [WARNING] Generating a MembersInjector or Factory for org.atinject.tck.auto.accessories.SpareTire. Prefer to run the dagger processor over that class instead.
[INFO] [WARNING] Generating a MembersInjector or Factory for org.atinject.tck.auto.Tire. Prefer to run the dagger processor over that class instead.
[INFO] [WARNING] Generating a MembersInjector or Factory for org.atinject.tck.auto.accessories.RoundThing. Prefer to run the dagger processor over that class instead.
[INFO] [WARNING] Generating a MembersInjector or Factory for org.atinject.tck.auto.Tire. Prefer to run the dagger processor over that class instead.
[INFO] [WARNING] Generating a MembersInjector or Factory for org.atinject.tck.auto.V8Engine. Prefer to run the dagger processor over that class instead.
[INFO] [WARNING] No processor claimed any of these annotations: org.atinject.tck.auto.Drivers,dagger.Component,dagger.Module,javax.inject.Named,javax.inject.Singleton,dagger.Provides
[INFO] [INFO] 13 warnings
[INFO] [INFO] -------------------------------------------------------------
[INFO] [INFO] -------------------------------------------------------------
[INFO] [ERROR] COMPILATION ERROR :
[INFO] [INFO] -------------------------------------------------------------
[INFO] [ERROR] …/google/dagger/compiler/target/it/tck/src/main/java/test/TckComponent.java:[12,7] test.TckComponent.car() contains a dependency cycle:
[INFO] test.TckModule.provideCar(org.atinject.tck.auto.Convertible convertible)
[INFO] [parameter: org.atinject.tck.auto.Convertible convertible]
[INFO] org.atinject.tck.auto.Convertible.driversSeatA
[INFO] [injected field of type: @org.atinject.tck.auto.Drivers org.atinject.tck.auto.Seat driversSeatA]
[INFO] test.TckModule.provideDriversSeat(org.atinject.tck.auto.DriversSeat driversSeat)
[INFO] [parameter: org.atinject.tck.auto.DriversSeat driversSeat]
[INFO] org.atinject.tck.auto.DriversSeat.<init>(org.atinject.tck.auto.accessories.Cupholder cupholder)
[INFO] [parameter: org.atinject.tck.auto.accessories.Cupholder cupholder]
[INFO] org.atinject.tck.auto.accessories.Cupholder.<init>(javax.inject.Provider<org.atinject.tck.auto.Seat> seatProvider)
[INFO] [parameter: javax.inject.Provider<org.atinject.tck.auto.Seat> seatProvider]
[INFO] org.atinject.tck.auto.Seat.<init>(org.atinject.tck.auto.accessories.Cupholder cupholder)
[INFO] [parameter: org.atinject.tck.auto.accessories.Cupholder cupholder]
[INFO] [INFO] 1 error
…so for now we cannot claim that Dagger 2 is “JSR 330 compliant”; it has (at least) one known deviation from the spec.
from dagger.
In dagger 2.0 the example from @niloc132 compilation ends with this error:
Error:(15, 13) error: LazyCycleBroken.MyComponent.app() contains a dependency cycle:
LazyCycleBroken.App.bar
[injected field of type: LazyCycleBroken.Bar bar]
LazyCycleBroken.Bar.lazyFoo
[injected field of type: dagger.Lazy<LazyCycleBroken.Foo> lazyFoo]
LazyCycleBroken.Foo.bar
[injected field of type: LazyCycleBroken.Bar bar]
Similar error is there using Provider
. In dagger1 cycles could have been broken using Lazy
or Provider
.
Is this solution permanent? Is there technical limitation why dagger 2 cannot have any kind of cycles? I have not found a place where this is documented.
from dagger.
Well this is going to take some consideration.
from dagger.
Related Issues (20)
- error when ksp.useKSP2=true HOT 2
- Suppress annotation on @Inject is not honored on the Factory HOT 1
- [KSP2] Dagger and Hilt incompatibility with KSP2 HOT 4
- [KSP2] NullPointerException: null cannot be cast to non-null type androidx.room.compiler.processing.XType HOT 1
- App crashing with NPE for some classes when Lazy Class Key is used HOT 7
- OutOfMemoryError with Maven HOT 1
- DaggerAppComponent not creating in the version 2.51.1 HOT 3
- java.lang.ClassNotFoundException: dagger.spi.shaded.androidx.room.compiler.processing.javac.JavacBasicAnnotationProcessor. Hilt 2.49+ HOT 1
- how to manually generate module HOT 1
- Explain how to add dagger jar files manually to the android project HOT 2
- Annotate interface with default Bind implementation HOT 2
- Transitive vulnerability from symbol-processing-api HOT 1
- java.lang.IllegalArgumentException: CreationExtras must have a value by `SAVED_STATE_REGISTRY_OWNER_KEY` HOT 4
- Update of different dependency: Error "package javax.annotation.processing is not visible" HOT 4
- Compile time error with KSP with Generics HOT 4
- java.lang.IllegalArgumentException: Multiple entries with same key HOT 4
- Execution failed for task ':app:kaptDebugKotlin'. > A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptWithoutKotlincTask$KaptExecutionWorkAction > java.lang.reflect.InvocationTargetException (no error message) HOT 2
- Stackoverflow when exposing parents of Subcomponents HOT 7
- Hilt not working with android testFixtures? HOT 2
- Hilt 2.44.2 - Class not found when use @AndroidEntryPoint at WidgetReceiver HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dagger.