eclipse GetAnnotation returns @NonNull

Viewed 71

I am trying to use the Eclipse org.eclipse.jdt.annotation.NonNull annotations and i don't understand this

method signature:

@NonNull MyAnnotation java.lang.reflect.Field.getAnnotation(Class<@NonNull MyAnnotation> annotationClass)
for loop:
if(field.getAnnotation(MyAnnotation.class)!=null)
    continue;

Eclipse declares the following code dead code

try{

Why does eclipse think the getAnnotation class returns @NonNull? The docs clearly state it can return null.

I have verified via a debugger that the code is not dead, stepping trough.

EDIT: I do not use @NonNullByDefault on any package

I tried:

  • adding @Nullable to MyAnnotation, i get The nullness annotation 'Nullable' is not applicable at this location
  • @Nullable MyAnnotation n=field.getAnnotation(MyAnnotation.class); still same problem
1 Answers

Got rid of the warning by adding the first line:

Class<MyAnnotation> c = MyAnnotation.class;

if(field.getAnnotation(c)!=null)
    continue;

After that i do not get the dead code warning.

Somehow Eclipse is adding the @NonNull annotation automatically to MyAnnotation.

Related