Revision: 88ee52dec992
Author: Sam Berlin <[email protected]>
Date: Sun Feb 26 18:22:30 2012
Log: Fix issue 670, keep values from MapBinder & Multibinder distinct.
Revision created by MOE tool push_codebase.
MOE_MIGRATION=4268
http://code.google.com/p/google-guice/source/detail?r=88ee52dec992
Modified:
/core/src/com/google/inject/internal/ProxyFactory.java
/core/test/com/google/inject/MethodInterceptionTest.java
/extensions/multibindings/src/com/google/inject/multibindings/RealElement.java
=======================================
--- /core/src/com/google/inject/internal/ProxyFactory.java Sat Jan 21
09:55:00 2012
+++ /core/src/com/google/inject/internal/ProxyFactory.java Sun Feb 26
18:22:30 2012
@@ -24,7 +24,6 @@
import com.google.common.collect.Maps;
import com.google.inject.spi.InjectionPoint;
-import net.sf.cglib.core.MethodWrapper;
import net.sf.cglib.proxy.Callback;
import net.sf.cglib.proxy.CallbackFilter;
import net.sf.cglib.proxy.Enhancer;
@@ -170,7 +169,7 @@
// to this injector. Otherwise, the proxies for each injector will
waste PermGen memory
try {
Enhancer enhancer = BytecodeGen.newEnhancer(declaringClass,
visibility);
- enhancer.setCallbackFilter(new IndicesCallbackFilter(methods));
+ enhancer.setCallbackFilter(new IndicesCallbackFilter(declaringClass,
methods));
enhancer.setCallbackTypes(callbackTypes);
return new ProxyConstructor<T>(enhancer, injectionPoint, callbacks,
interceptors);
} catch (Throwable e) {
@@ -199,35 +198,35 @@
}
/**
- * A callback filter that maps methods to unique IDs. We define equals
and
- * hashCode without using any state related to the injector so that
enhanced
- * classes intercepting the same methods can be shared between injectors
(and
- * child injectors, etc).
+ * A callback filter that maps methods to unique IDs. We define equals
and hashCode using the
+ * declaring class so that enhanced classes can be shared between
injectors.
*/
private static class IndicesCallbackFilter implements CallbackFilter {
- final Map<Object, Integer> indices;
- final int hashCode;
-
- IndicesCallbackFilter(List<Method> methods) {
- final Map<Object, Integer> indices = Maps.newHashMap();
+ final Class<?> declaringClass;
+ final Map<Method, Integer> indices;
+
+ IndicesCallbackFilter(Class<?> declaringClass, List<Method> methods) {
+ this.declaringClass = declaringClass;
+ final Map<Method, Integer> indices = Maps.newHashMap();
for (int i = 0; i < methods.size(); i++) {
- indices.put(MethodWrapper.create(methods.get(i)), i);
- }
+ Method method = methods.get(i);
+ indices.put(method, i);
+ }
+
this.indices = indices;
- this.hashCode = indices.hashCode();
}
public int accept(Method method) {
- return indices.get(MethodWrapper.create(method));
+ return indices.get(method);
}
@Override public boolean equals(Object o) {
return o instanceof IndicesCallbackFilter &&
- ((IndicesCallbackFilter) o).indices.equals(indices);
+ ((IndicesCallbackFilter) o).declaringClass == declaringClass;
}
@Override public int hashCode() {
- return hashCode;
+ return declaringClass.hashCode();
}
}
=======================================
--- /core/test/com/google/inject/MethodInterceptionTest.java Sat Jan 21
09:55:00 2012
+++ /core/test/com/google/inject/MethodInterceptionTest.java Sun Feb 26
18:22:30 2012
@@ -79,7 +79,7 @@
Interceptable nullFoosOne = childOne.getInstance(Interceptable.class);
assertNotNull(nullFoosOne.bar());
- assertNull(nullFoosOne.foo()); // confirm it's being intercepted
+ assertNull(nullFoosOne.foo());
Injector childTwo = injector.createChildInjector(new AbstractModule() {
protected void configure() {
@@ -88,21 +88,10 @@
});
Interceptable nullFoosTwo = childTwo.getInstance(Interceptable.class);
- assertNull(nullFoosTwo.foo()); // confirm it's being intercepted
+ assertNull(nullFoosTwo.foo());
assertSame("Child injectors should share proxy classes, otherwise
memory leaks!",
nullFoosOne.getClass(), nullFoosTwo.getClass());
-
- Injector injector2 = Guice.createInjector(new AbstractModule() {
- protected void configure() {
- bindInterceptor(Matchers.any(), Matchers.returns(only(Foo.class)),
- new ReturnNullInterceptor());
- }
- });
- Interceptable separateNullFoos =
injector2.getInstance(Interceptable.class);
- assertNull(separateNullFoos.foo()); // confirm it's being intercepted
- assertSame("different injectors should share proxy classes, otherwise
memory leaks!",
- nullFoosOne.getClass(), separateNullFoos.getClass());
}
public void testGetThis() {
=======================================
---
/extensions/multibindings/src/com/google/inject/multibindings/RealElement.java
Sat Jan 21 08:06:49 2012
+++
/extensions/multibindings/src/com/google/inject/multibindings/RealElement.java
Sun Feb 26 18:22:30 2012
@@ -44,7 +44,7 @@
}
public Type type() {
- return type;
+ return type;
}
public Class<? extends Annotation> annotationType() {
--
You received this message because you are subscribed to the Google Groups
"google-guice-dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice-dev?hl=en.