Skip to content
This repository has been archived by the owner on Aug 26, 2021. It is now read-only.

Broken binding when providing an auto-factory generated implementation without a fully qualified class name. #456

Open
CoatedMoose opened this issue Jan 12, 2015 · 9 comments

Comments

@CoatedMoose
Copy link

I am pretty sure this is a dagger issue and not an google/auto one, but feel free to correct me.

When trying to provide an implementation of an interface:

import com.example.ExampleClassImplFactory;
@Module(...)
public class ExampleModule {
    @Provides
    ExampleClassFactory provideExampleClass(ExampleClassImplFactory impl) {
        return impl;
    }
}

Where the implementation is the result of an AutoFactory, I get this exception (at runtime - issues at compile time):

Caused by: java.lang.IllegalStateException: Could not load class ExampleClassImplFactory needed for binding ExampleClassImplFactory
    at dagger.internal.FailoverLoader.getAtInjectBinding(FailoverLoader.java:68)
    at dagger.internal.Linker.createBinding(Linker.java:225)
    at dagger.internal.Linker.linkRequested(Linker.java:142)
    at dagger.ObjectGraph$DaggerObjectGraph.getInjectableTypeBinding(ObjectGraph.java:336)
    at dagger.ObjectGraph$DaggerObjectGraph.inject(ObjectGraph.java:306)
...

The following works:

@Module(...)
public class ExampleModule {
    @Provides
    ExampleClassFactory provideExampleClass(com.example.ExampleClassImplFactory impl) {
        return impl;
    }
}

I assume the issue is that auto factory hasn't generated the class yet when dagger processes the @Provides method and maybe adding an implied reference the the fully qualified package name would help.

@CoatedMoose
Copy link
Author

@gk5885
Copy link
Contributor

gk5885 commented Jan 12, 2015

There have been major changes in Dagger 2 to address these types of issues. Presumably, if someone were to migrate the Dagger 1 processors to extend BasicAnnotationProcessor this would get resolved.

@CoatedMoose
Copy link
Author

I do not know which BasicAnnotationProcessor you are referring to. A search for filenames hasn't yielded any results (checked square/dagger and google/dagger).

@gk5885
Copy link
Contributor

gk5885 commented Jan 13, 2015

In that case, we need @cgruber to do a sync with the google repo.

@digitalbuddha
Copy link

Came here from SO question, I'm using Dagger 2 with AutoFactory and seeing same behavior, only works with fully qualified names.

    @Provides
    ABManager provideABManagerImpl(com.example.android.ab.ABManagerImplFactory factory ) {
        return factory.create(3, IMMEDIATELY);
    }

@JakeWharton
Copy link
Collaborator

This is not the repository for Dagger 2. You want
https://github.com/google/dagger

On Mon, Oct 12, 2015 at 11:28 PM Mike Nakhimovich [email protected]
wrote:

Came here from SO question, I'm using Dagger 2 with AutoFactory and seeing
same behavior, only works with fully qualified names.

@Provides
ABManager provideABManagerImpl(com.nytimes.android.ab.ABManagerImplFactory factory ) {
    return factory.create(3, IMMEDIATELY);
}


Reply to this email directly or view it on GitHub
#456 (comment).

@digitalbuddha
Copy link

@gk5885 mentions that Dagger 2 has resolved the issue, I thought it might be worth noting that extending BasicAnnotationProcessor does not fix this.

tbroyer pushed a commit to tbroyer/dagger that referenced this issue Sep 8, 2016
…684005f94867c54a07e824985836d845ce654

Moe sync 9/6
@jag4364u
Copy link

jag4364u commented Oct 7, 2016

@digitalbuddha as you mentioned factory classes works with fully qualified names ! for me still it is not working. do you any other suggestion on this to make it work? i am using dagger<2.5> . please help.

@cgruber
Copy link
Collaborator

cgruber commented Oct 12, 2016

As was mentioned, Dagger 2.x is on the http://github.com/google/dagger project. The square project
is for Dagger 1.x

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants