public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if ( values.containsKey( method.getName() ) ) {
return values.get( method.getName() );
}
return method.invoke( this, args );
}
When equals() is called via the dynamic Proxy, the eventual invocation is a call to Object.equals(). The problem is that the left-hand argument is *this* - an AnnotationProxy instance, and the right-hand argument is a dynamic Proxy instance. Object.equals() therefore always returns false.
This simple piece of code shows the broken call to equals() clearly.
{code:title=Test.java|borderStyle=solid}
AnnotationDescriptor<DecimalMin> descriptor =
new AnnotationDescriptor<DecimalMin>(DecimalMin.class);
descriptor.setValue("message", "some message");
descriptor.setValue("value", "1");
AnnotationProxy proxy = new AnnotationProxy(descriptor);
Annotation annotation = (Annotation)Proxy.newProxyInstance(
DecimalMin.class.getClassLoader(),
new Class[] { DecimalMin.class },
proxy);
System.out.println(annotation.equals(annotation));