AnnotationInvocationHandler - null check for hashCode / equals / toString computation?
rafael.wth at gmail.com
Fri Nov 14 09:51:53 UTC 2014
For reasons I am not going into, I am implementing my own
AnnotationInvocationHandler and I want it to be compatible to the OpenJDK's
annotation invocation handler with respect to the hash code and equals
functionality, thus I just looked at the source in more detail. During
implementing the handler, I realized that:
1. The invoke method applies a null check for an annotation value when
looking it up for explicitly reading an annotation property and throws an
IncompleteAnnotationException if no value and no default value is provided.
2. No such checks are applied when invoking the hashCode / equals /
toString methods for the annotation which all have their own handler
method. This would result in a NullPointerException for all of them.
I did not find any formal specification for what is supposed to happen. Is
it correct to throw these exceptions or should it rather also be an
Thanks for the info! Rafael
More information about the core-libs-dev