Back to Intellij Community

ReflectionForUnavailableAnnotation

java/java-impl/resources/inspectionDescriptions/ReflectionForUnavailableAnnotation.html

2025.3-rc-2459 B
Original Source

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 {}