@Retention(Runtime) annotations silently omitted if not in classpath?
dawid.weiss at gmail.com
Thu Nov 24 14:34:09 PST 2011
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,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the type-annotations-dev