2 new revisions:
Revision: 94c2d2c6c53c
Author: Christian Edward Gruber <cgru...@google.com>
Date: Wed May 15 19:05:25 2013
Log: Suppress a warning in advance that will be a run-time error in
Guice i...
http://code.google.com/p/google-guice/source/detail?r=94c2d2c6c53c
Revision: 45d86df69be9
Author: Christian Edward Gruber <cgru...@google.com>
Date: Wed May 15 19:11:47 2013
Log: Fix http://code.google.com/p/google-guice/issues/detail?id=742 by
havi...
http://code.google.com/p/google-guice/source/detail?r=45d86df69be9
==============================================================================
Revision: 94c2d2c6c53c
Author: Christian Edward Gruber <cgru...@google.com>
Date: Wed May 15 19:05:25 2013
Log: Suppress a warning in advance that will be a run-time error in
Guice in a subsequent commit, and which will be added to error-prone and
caught at compile-time for those who use it.
------------------
Manually Synced.
COMMIT=43228490
http://code.google.com/p/google-guice/source/detail?r=94c2d2c6c53c
Modified:
/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryModuleBuilderTest.java
=======================================
---
/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryModuleBuilderTest.java
Thu Jul 7 17:34:16 2011
+++
/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryModuleBuilderTest.java
Wed May 15 19:05:25 2013
@@ -478,6 +478,7 @@
AssistedSingleton create(String string);
}
+ @SuppressWarnings("GuiceAssistedInjectScoping")
@Singleton
static class AssistedSingleton {
@Inject
==============================================================================
Revision: 45d86df69be9
Author: Christian Edward Gruber <cgru...@google.com>
Date: Wed May 15 19:11:47 2013
Log: Fix http://code.google.com/p/google-guice/issues/detail?id=742 by
having assistedinject fail if the target implementation class has a scop
ing annotation on it. Scope annotations on assistedinject targets were
always ignored by Guice, and allowing them on the classes led to lots of
confusion when reading code. The new behavior makes for much more readable
code.
This could potentially cause runtime errors at injector creation time if
you accidentally had scoping annotations on the implementation class. The
fix is just to remove that scoping annotation -- there will be no change in
behavior, because the scope was ignored.
There is an extreme edge case where this change may cause a problem, but it
creates sufficiently confusing code that we are OK with turning it into a
failure: You used assistedinject yet had no assisted parameters, and
sometimes injected the object directly and other times constructed it
through the factory. When injecting directly, it would adhere to the
scope, but when constructing through the factory it would create a new
instance every time. ... If you *really* wanted this behavior, the
workaround would be to bind using toConstructor in Scopes.NO_SCOPE to a
named(unscoped) version of the class, which is also more expressive. (But,
more often than not, what you really wanted was to *not do this*.)
------------------
Manually Synced.
COMMIT=43242119
http://code.google.com/p/google-guice/source/detail?r=45d86df69be9
Modified:
/extensions/assistedinject/src/com/google/inject/assistedinject/FactoryProvider2.java
/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryModuleBuilderTest.java
=======================================
---
/extensions/assistedinject/src/com/google/inject/assistedinject/FactoryProvider2.java
Thu Jul 7 17:34:16 2011
+++
/extensions/assistedinject/src/com/google/inject/assistedinject/FactoryProvider2.java
Wed May 15 19:11:47 2013
@@ -241,6 +241,15 @@
if(implementation == null) {
implementation = returnType.getTypeLiteral();
}
+ 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);
+ }
+
InjectionPoint ctorInjectionPoint;
try {
ctorInjectionPoint =
=======================================
---
/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryModuleBuilderTest.java
Wed May 15 19:05:25 2013
+++
/extensions/assistedinject/test/com/google/inject/assistedinject/FactoryModuleBuilderTest.java
Wed May 15 19:11:47 2013
@@ -462,16 +462,22 @@
}
public void testSingletonScopeOnAssistedClassIsIgnored() {
- // production stage is important, because it will trigger eager
singleton creation
- Injector injector = Guice.createInjector(Stage.PRODUCTION, new
AbstractModule() {
+ try {
+ Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
install(new FactoryModuleBuilder().build(SingletonFactory.class));
}
});
-
- SingletonFactory factory =
injector.getInstance(SingletonFactory.class);
- assertNotSame(factory.create("foo"), factory.create("bar"));
+ fail();
+ } catch (CreationException ce) {
+ assertEquals(1, ce.getErrorMessages().size());
+ assertEquals("Found scope annotation [" + Singleton.class.getName()
+ "]"
+ + " on implementation class [" +
AssistedSingleton.class.getName() + "]"
+ + " of AssistedInject factory [" +
SingletonFactory.class.getName() + "]."
+ + "\nThis is not allowed, please remove the scope annotation.",
+ Iterables.getOnlyElement(ce.getErrorMessages()).getMessage());
+ }
}
interface SingletonFactory {
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to google-guice-dev+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice-dev@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.