Inspectopedia
 
2024.3

Reflective access to a source-only annotation

Warning
New
Last modified: 03 December 2024

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:

This inspection depends on the Java feature 'Annotations', which is available since Java 5.