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)
- Subcomponent MembersInjector error in 2.51 HOT 1
- Does Hilt always execute app module during instrumented test? HOT 3
- [KSP] Dagger-KSP does not see typealiased dagger annotations HOT 3
- Cannot invoke getAnnotationValue because "annotation" is null HOT 14
- Creator-less subcomponents are not visible to modules HOT 1
- Suggestion to add isInit() api to dagger.Lazy HOT 1
- [Error] : java.lang.ClassNotFoundException: Didn't find class "com.myproject.MainApplication" on path: DexPathList HOT 1
- K2 KAPT (aka KAPT4) doesn't like inline/reified. HOT 3
- [KSP2] ClassCastException: class KSClassDeclarationEnumEntryImpl cannot be cast to class XEnumEntry HOT 2
- Hilt: Injection not working in BroadcastReceiver HOT 3
- Assisted injection appears to not work correctly in some cases HOT 3
- [Dagger/MissingBinding] com.xxx.onboarding.presentation.otp.LoginViewModel cannot be provided without an @Inject constructor or an @Provides-annotated method. public abstract static class SingletonC implements SemaaiApplication_GeneratedInjector HOT 1
- Hilt Class Generation Fails After Upgrading to AGP 8.5.1 from 8.0.1 HOT 6
- Issue with Dagger Hilt Upgrade from 2.48 to 2.49 - Unable to Load Class JavacBasicAnnotationProcessor HOT 1
- Way to replace a dependency created using Constructor Injection for all tests using Hilt. HOT 4
- After updating from 2.51.1 to 2.52, my GWT application does not compile
- NPE On Lazy Dagger
- [KSP] Component processing is not deferred if there are unresolved symbols in the current round HOT 2
- [KAPT] - Issue build type release AGP 8.4.0 - 8.5.2 Kotlin 1.9.24 and Dagger 2.52
- SomeClass$LazyClassKeyProviders.class generated by Dagger/Hilt is not deterministic
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.