Java
Reflective access to a source-only annotation
Warning
New
Last modified: 03 December 2024Reports 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 {}
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
ReflectionForUnavailableAnnotation
This inspection depends on the Java feature 'Annotations', which is available since Java 5.
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Java, 243.23126 |
Thanks for your feedback!
Was this page helpful?