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

AssistedInject inconsistency for Singleton return types #742

Closed
gissuebot opened this issue Jul 7, 2014 · 4 comments
Closed

AssistedInject inconsistency for Singleton return types #742

gissuebot opened this issue Jul 7, 2014 · 4 comments
Labels

Comments

@gissuebot
Copy link

From bahri.gencsoy on February 15, 2013 04:57:01

FactoryModuleBuilder doesn't respect Singleton annotations of returned types. I know this is not the intended usage of FactoryModuleBuilder but due to refactorings we encountered this situtation on site. It could have failed early instead of creating new types.

Following unit test fails, instead of throwing an exception during injector creation:

public class FactoryModuleBuilderSingletonTest {

    @Singleton
    public static class ASingleton {

    }

    public static interface SingletonsFactory {
        ASingleton getSingleton();
    }

    @Test
    public void factoryModuleBuilderShouldRespectSingleton() {
        Injector injector = Guice.createInjector(new AbstractModule() {
            @Override
            protected void configure() {
                install(new FactoryModuleBuilder().build(SingletonsFactory.class));
            }
        });
        assertSame(injector.getInstance(ASingleton.class), injector.getInstance(ASingleton.class));
        assertSame(injector.getInstance(ASingleton.class), injector.getInstance(SingletonsFactory.class).getSingleton());
    }
}

Original issue: http://code.google.com/p/google-guice/issues/detail?id=742

@gissuebot
Copy link
Author

From sberlin on February 15, 2013 06:34:24

I agree outright failing would be better, but I'm kinda scared to try changing it.  I'll give it a go over Google's code and see how bad the fallout is.

@gissuebot
Copy link
Author

From sberlin on February 28, 2013 13:20:57

FYI, I've fixed this internally.  Once we manage to fix our sync procedure, we'll push it out to this repository.

For reference, the change is simply adding:
        Class<? extends Annotation> scope =
            Annotations.findScopeAnnotation(errors, implementation.getRawType());
        if (scope != null) {
          errors.addMessage("Found scope annotation [%s] on implementation class "
              + "[%s] of AssistedInject factory [%s].\nThis is not allowed, please"
              + " remove the scope annotation.",
              scope, implementation.getRawType(), factoryType);
        }

around line 244 of FactoryProvider2.java.

Status: Fixed

@gissuebot
Copy link
Author

From bahri.gencsoy on March 29, 2013 02:31:27

Thanks.

@gissuebot
Copy link
Author

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

No branches or pull requests

1 participant