@Retention(Runtime) annotations silently omitted if not in classpath?
Dawid Weiss
dawid.weiss at gmail.com
Thu Nov 24 14:34:09 PST 2011
Hi everyone,
I just discovered that Method#getDeclaredAnnotations() may or may not
return an annotation with @Retention(RetentionPolicy.RUNTIME). Basically
what happens is if the annotation class is present in classpath, it is
returned. But if it isn't present in classpath, the returned array simply
omits the missing annotation.
I looked at the JLS and jsr-202 (class file format) but I can't find any
fragment relevant to this -- where are the rules governing this? I found
bits and pieces in the following places:
* AnnotatedElement (TypeNotPresentException thrown if an annotation
references a Class explicitly, not the case here),
* OpenJDK's AnnotationParser source code -- there is clearly a distinction
in the code between throwing/ not throwing a TypeNotPresentException, but
no specific pointers to the rules.
I would appreciate if somebody shared a link or info to where the rules of
throw/not throw are explained. Thanks in advance,
Dawid
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/type-annotations-dev/attachments/20111124/254afe79/attachment.html
More information about the type-annotations-dev
mailing list