Properly handle Object methods in AutoBeanFactory in the JVM This fixes a ClassCastException when calling #toString(): the factory handler assumed any method other than the ones explicitly handled would be returning a parameterized type (AutoBean<Foo>). Additionally it also makes it possible to invoke #hashCode() and #equals(). Change-Id: I140c9b2c56ed2e632a06433d38c3e1daaea11025
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 8532f41..e80fd8a 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
@@ -50,6 +50,11 @@ Class<?> beanType; Object toWrap = null; String name = method.getName(); + if (BeanMethod.OBJECT.matches(method)) { + // Redirect all methods of Object early on + return method.invoke(this, args); + } + if (name.equals("create")) { // Dynamic create. Guaranteed to have at least one argument // create(clazz); or create(clazz, toWrap);
diff --git a/user/test/com/google/web/bindery/autobean/gwt/client/AutoBeanTest.java b/user/test/com/google/web/bindery/autobean/gwt/client/AutoBeanTest.java index bc9a6c5..76150f1 100644 --- a/user/test/com/google/web/bindery/autobean/gwt/client/AutoBeanTest.java +++ b/user/test/com/google/web/bindery/autobean/gwt/client/AutoBeanTest.java
@@ -584,6 +584,20 @@ } } + public void testFactoryToString() { + assertNotNull(factory.toString()); + } + + public void testFactoryHashCode() { + assertTrue(factory.hashCode() != 0); + assertEquals(factory.hashCode(), factory.hashCode()); + } + + public void testFactoryEquals() { + assertFalse(factory.equals(null)); + assertTrue(factory.equals(factory)); + } + @Override protected void gwtSetUp() throws Exception { factory = GWT.create(Factory.class);