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)
- [KSP] dagger-android hanging indefinitely on a large multi module project HOT 2
- Optional bindings in a parent component can sometimes use bindings from child components HOT 2
- NullPointerException dagger.spi.shaded.androidx.room.compiler.processing.XTypeElement.getAnnotation HOT 6
- Problem with Injection of DAO HOT 1
- error: [Hilt] Could not get element for com.foo.viewModels.FooViewModel_HiltModules.BindsModule: java.lang.NullPointerException HOT 1
- Missing release notes for 2.51 HOT 1
- `LazyClassKey` doesn't work when providing a `Map<Class<*>, Provider<?>` with a scope
- @AssistedInject in ViewModel using Dagger (NOT Hilt, just dagger) does not compile: cannot be provided without an @Inject constructor or an @Provides-annotated method HOT 6
- [issue] Dagger doesn't compile or doesn't give a right error message when ViewModelFactory is implemened on Kotlin rather than on Java HOT 4
- Having an issue with Dagger Hilt Proguard Rules HOT 12
- Following dagger.dev tutorial doesnt create singleton in v2.51 HOT 2
- Multibinding with Nested Complex Keys uses the wrong AnnotationCreator HOT 1
- [Hilt] onCreate() in my Application doesn't called on Instrument test HOT 4
- [Dagger-Hilt] Error when applying obfuscation other than Proguard (Allatori) HOT 3
- error: [Hilt] Expected @AndroidEntryPoint to have a value HOT 3
- @IntoSet analog for injectable classes HOT 3
- Hilt Generated Code having not used code? HOT 2
- [Dagger-Hilt] Can't get viewModel in composable by Hilt HOT 1
- Why does Provides in a Companion Object work? HOT 5
- Update Dagger guava dependency to address CVE-2023-2976 HOT 2
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.