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

luboskrnac picture luboskrnac · Nov 18, 2015 · Viewed 8.3k times · Source

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?

Answer

luboskrnac picture luboskrnac · Nov 18, 2015

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>