Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The type org.eclipse.jdt.annotation.NonNull cannot be resolved. It is indirectly referenced from required .class files

When I use the Java 8 method reference double colon operator (::) with new operator (e.g. MyType::new), I get this error in Eclipse of Spring Tool suite (STS):

The type org.eclipse.jdt.annotation.NonNull cannot be resolved. It is indirectly referenced from required .class files

How to get rid of this error?

like image 912
luboskrnac Avatar asked Nov 18 '15 16:11

luboskrnac


2 Answers

Error description is provided in Stephan Herrmann's comment. There is open Eclipse issue to make this issue more user friendly.

Solution is to include following dependency:

<dependency>
    <groupId>org.eclipse.jdt</groupId>
    <artifactId>org.eclipse.jdt.annotation</artifactId>
    <version>2.0.0</version>
</dependency>
like image 96
luboskrnac Avatar answered Nov 19 '22 18:11

luboskrnac


Eclipse has a feature called annotation-based null analysis, which provides compile-time checks using annotations (e.g. @NonNull or @Nullable). You get this error when annotations are missing in the classpath.

If you don't plan to use the annotation-based null analysis feature, you can just disable it in Eclipse.

Open the global or project settings and go to Java > Compiler > Warnings. In the Null analysis category, uncheck Enable annotation-based null analysis. Then rebuild the workspace and those errors won't show again.

like image 17
kapex Avatar answered Nov 19 '22 19:11

kapex