You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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();
}
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.
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);
}
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 {
@
Singletonpublic static class ASingleton {
}
public static interface SingletonsFactory {
ASingleton getSingleton();
}
@
Testpublic void factoryModuleBuilderShouldRespectSingleton() {
Injector injector = Guice.createInjector(new AbstractModule() {
@
Overrideprotected 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
The text was updated successfully, but these errors were encountered: