Issue 742 in google-guice: AssistedInject inconsistency for Singleton return types

5 views
Skip to first unread message

google...@googlecode.com

unread,
Feb 15, 2013, 4:57:11 AM2/15/13
to google-g...@googlegroups.com
Status: New
Owner: ----

New issue 742 by bahri.ge...@gmail.com: AssistedInject inconsistency for
Singleton return types
http://code.google.com/p/google-guice/issues/detail?id=742

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());
}
}

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

google...@googlecode.com

unread,
Feb 15, 2013, 9:34:44 AM2/15/13
to google-g...@googlegroups.com

Comment #1 on issue 742 by sberlin: AssistedInject inconsistency for
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.

google...@googlecode.com

unread,
Feb 28, 2013, 4:21:09 PM2/28/13
to google-g...@googlegroups.com
Updates:
Status: Fixed

Comment #2 on issue 742 by sberlin: AssistedInject inconsistency for
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.

google...@googlecode.com

unread,
Mar 29, 2013, 5:31:38 AM3/29/13
to google-g...@googlegroups.com

Comment #3 on issue 742 by bahri.ge...@gmail.com: AssistedInject
inconsistency for Singleton return types
http://code.google.com/p/google-guice/issues/detail?id=742

Thanks.

google...@googlecode.com

unread,
May 16, 2013, 2:44:05 PM5/16/13
to google-g...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages