@@ -23,6 +23,19 @@ class AccessorInvocationHandler<T> implements InvocationHandler {
2323
2424 private static final Object [] NO_ARGS = new Object [0 ];
2525
26+ private static final Method TO_STRING ;
27+ private static final Method EQUALS ;
28+ private static final Method HASH_CODE ;
29+ static {
30+ try {
31+ TO_STRING = Object .class .getMethod ("toString" );
32+ EQUALS = Object .class .getMethod ("equals" , Object .class );
33+ HASH_CODE = Object .class .getMethod ("hashCode" );
34+ } catch (NoSuchMethodException e ) {
35+ throw new AssertionError (e ); // Can't happen
36+ }
37+ }
38+
2639 private final AccessorMapper <T > mapper ;
2740
2841 private final Map <Method , MethodMapper > methodMap = new HashMap <Method , MethodMapper >();
@@ -35,11 +48,20 @@ class AccessorInvocationHandler<T> implements InvocationHandler {
3548 }
3649
3750 public Object invoke (Object proxy , Method m , Object [] args ) throws Throwable {
51+ if (m .equals (TO_STRING ))
52+ return mapper .daoClass .getSimpleName () + " implementation generated by the Cassandra driver mapper" ;
53+
54+ // It's unlikely that equals and hashCode will be used on accessor implementations, but better safe than sorry.
55+ // Identity equality is enough, given that the mapper always returns the same instance for a given accessor.
56+ if (m .equals (EQUALS ))
57+ return proxy == args [0 ];
58+
59+ if (m .equals (HASH_CODE ))
60+ return System .identityHashCode (proxy );
3861
3962 MethodMapper method = methodMap .get (m );
40- if (mapper == null )
63+ if (method == null )
4164 throw new UnsupportedOperationException ();
42-
4365 return method .invoke (args == null ? NO_ARGS : args );
4466 }
4567}
0 commit comments