Fix AutoBeanFactory#equals in the JVM
factory.equals(factory) routed the equals to the InvocationHandler,
which would then compare an InvocationHandler to a proxy object using
the default Object#equals() implementation. Equals thus needs to be
overridden to extract the InvocationHandler out of the passed in object
when it is a proxy, before handing it to super.equals().
Change-Id: Ibd192631736751dc5dc4f536ed12865eae60a51d
diff --git a/user/src/com/google/web/bindery/autobean/vm/impl/FactoryHandler.java b/user/src/com/google/web/bindery/autobean/vm/impl/FactoryHandler.java
index e80fd8a..7a21a9d 100644
--- a/user/src/com/google/web/bindery/autobean/vm/impl/FactoryHandler.java
+++ b/user/src/com/google/web/bindery/autobean/vm/impl/FactoryHandler.java
@@ -24,6 +24,7 @@
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Proxy;
/**
* Handles dispatches on AutoBeanFactory interfaces.
@@ -96,6 +97,19 @@
return toReturn;
}
+ @Override
+ public boolean equals(Object other) {
+ if (other != null && Proxy.isProxyClass(other.getClass())) {
+ other = Proxy.getInvocationHandler(other);
+ }
+ return super.equals(other);
+ }
+
+ @Override
+ public final int hashCode() {
+ return super.hashCode();
+ }
+
/**
* EnumMap support.
*/