Archie Cobbs wrote:
Olivier Jolly wrote:
[...]
What does the failure look like?
Within an InvocationHandler, the method instance which is given as
parameter is not equals to Object.class.getDeclaredMethod("...", ...)
if the interface the proxy is built on redefines one of the "core"
Object methods. Easymock is correctly expecting to catch all "equals"
call with Object.class.getDeclaredMethod("equals", new Class[]
{Object.class}).equals(method) which is not the case without my patch.
Still curious.. :-)
It's not an error for an interface to declare a method that matches
an Object method (such as equals), and then for some bytecode somewhere
to INVOKEINTERFACE that method, even though INVOKEVIRTUAL would "make
more sense". E.g. code somewhere in Eclipse does this.
No, it's not an error and it actually mostly works just like everyone
expects it to. Excepted that Sun stated special cases in the javadoc of
Proxy :
"An invocation of the hashCode, equals, or toString methods declared in
java.lang.Object on a proxy instance will be encoded and dispatched to
the invocation handler's invoke method in the same manner as interface
method invocations are encoded and dispatched, as described above. The
declaring class of the Method object passed to invoke will be
java.lang.Object."
So isn't this an easymock bug? In such a case, wouldn't easymock fail
to catch a valid equals() invocation?
Seen the javadoc, I think that easymock devs did the right thing and
maybe that Java designers did this on that very purpose : catching all
core methods in an InvocationHandler is easy
-Archie
Olivier