Reflection looks for an annotation that is not retained at run time, so it is never found

tx0/java:invisible-annotation-lookupdefaulterrorbug

What it finds

Reflection sees only annotations with RUNTIME retention. An annotation type without a @Retention is kept in the class file but not loaded, and @Override and @SuppressWarnings are dropped by the compiler, as java.lang.annotation.Retention documents. method.isAnnotationPresent(Override.class) is therefore always false.

Reported is isAnnotationPresent, getAnnotation, getDeclaredAnnotation, getAnnotationsByType or getDeclaredAnnotationsByType with the class literal of Override, SuppressWarnings, or an annotation type declared in this file whose retention is not RUNTIME.

From the rule's source, invisible_annotation_lookup.rs.

Example from the rule's tests
import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.reflect.Method; class Scanner {  @interface Marker {}   @Retention(RetentionPolicy.RUNTIME)  @interface Visible {}   boolean scan(Method method) {    boolean a = method.isAnnotationPresent(Override.class);tx0 reports: @Override is not retained at run time    boolean b = method.getAnnotation(Marker.class) != null;tx0 reports: @Marker is not retained    boolean c = method.isAnnotationPresent(Visible.class);    boolean d = method.isAnnotationPresent(Deprecated.class);    return a || b || c || d;  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/java:invisible-annotation-lookup" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:invisible-annotation-lookup] reason="..."

tx0 explain tx0/java:invisible-annotation-lookup shows the same in the terminal. Found a false positive? Report it.