Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module with generic fails to find the target #135

Open
kokeroulis opened this issue Jul 8, 2019 · 2 comments
Open

Module with generic fails to find the target #135

kokeroulis opened this issue Jul 8, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@kokeroulis
Copy link

kokeroulis commented Jul 8, 2019

When we have a module with a generic type then dagger-reflect fails to resolve this dependency. For example given that we have the following module

@Module
public abstract class BaseActivityBindingModule<T extends Activity> {

    @Binds
    public abstract Activity bindActivity(T activity);
}

We will receive the following exception

java.lang.IllegalStateException: Missing binding for T
 * Requested: android.app.Activity
     from @Binds[com.example.BaseActivityBindingModule.bindActivity(…)]
 * Requested: T
     which was not found.
	at dagger.reflect.Linker.failure(Linker.java:52)
	at dagger.reflect.Linker.get(Linker.java:22)
	at dagger.reflect.UnlinkedBindsBinding.link(UnlinkedBindsBinding.java:26)
	at dagger.reflect.Linker.link(Linker.java:35)
	at dagger.reflect.Scope.link(Scope.java:143)
	at dagger.reflect.Scope.findExistingBinding(Scope.java:101)
	at dagger.reflect.Scope.findBinding(Scope.java:69)
	at dagger.reflect.Scope.getBinding(Scope.java:39)
	at dagger.reflect.ReflectiveMembersInjector.create(ReflectiveMembersInjector.java:61)
	at dagger.reflect.UnlinkedJustInTimeBinding.link(UnlinkedJustInTimeBinding.java:41)
	at dagger.reflect.Linker.link(Linker.java:35)
	at dagger.reflect.Scope.link(Scope.java:143)
	at dagger.reflect.Scope.putJitBinding(Scope.java:136)
	at dagger.reflect.Scope.findBinding(Scope.java:76)
	at dagger.reflect.Scope.getBinding(Scope.java:39)
	at dagger.reflect.ReflectiveMembersInjector.create(ReflectiveMembersInjector.java:61)
	at dagger.reflect.ReflectiveAndroidInjector$Factory.create(ReflectiveAndroidInjector.java:50)
	at dagger.android.DispatchingAndroidInjector.maybeInject(DispatchingAndroidInjector.java:111)
	at dagger.android.DispatchingAndroidInjector.inject(DispatchingAndroidInjector.java:134)
	at dagger.android.AndroidInjection.inject(AndroidInjection.java:63)
	at com.example.ExampleActivity.onCreate(ExampleActivity.java:25)

We can reproduce this by running ./gradlew :integration-tests:android:testReflectDebugUnitTest

For the above scenario I have created a sample project which is reproducing this issue, you can find the full source code here, the branch name is atsiap/module_with_generic.

Dagger's original code generation works properly and it can be verified by running ./gradlew :integration-tests:android:testCodegenDebugUnitTest.

@JakeWharton
Copy link
Owner

A bunch of the Dagger functional tests cover this and are currently muted. Hope to get to it eventually, but it's probably non-trivial.

@JakeWharton JakeWharton added the bug Something isn't working label Jul 9, 2019
@catellie
Copy link

catellie commented Nov 5, 2020

In my experience, this is the only major blocker for using dagger-reflect in non-trivial projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants