AnnotationInvocationHandler - null check for hashCode / equals / toString computation?

joe darcy joe.darcy at oracle.com
Sun Nov 16 18:20:15 UTC 2014


Hello,

The reference type members of annotations are all required to be non-null.

Cheers,

-Joe

On 11/14/2014 1:51 AM, Rafael Winterhalter wrote:
> 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
> IncompleteAnnotationException?
>
> Thanks for the info! Rafael




More information about the core-libs-dev mailing list