Reflective access to a source-only annotation
Reports attempts to reflectively check for the presence of a non-runtime annotation.
Using Class.isAnnotationPresent()
to test for an annotation whose retention policy is set to SOURCE
or CLASS
(the default) will always have a negative result. This mistake is easy to overlook.
Example:
{
getClass().isAnnotationPresent(SourceAnnotation.class); //always false
}
@Retention(RetentionPolicy.SOURCE)
@interface SourceAnnotation {}
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Java, 233.SNAPSHOT |
Last modified: 13 July 2023