Question about Nullable annotation

Started by iamcreasy, May 27, 2018, 00:32:33

Previous topic - Next topic

iamcreasy

Whenever I open lwjgl source in IntellijIDEA, the IDE reports that it can not resolve Nullable symbol,

The IDE suggest me to add the following annotation,
"java.lang.deprecated
org.jetbrains.annotations.Nullable
org.jetbrains.annotations.NotNull"

Here is a screenshot: https://imgur.com/YOx3SCh

Since the code compiles and runs fine, should I worry about it? Should I just import one of these 3 options to resolve the issue?

KaiHH

Since the LWJGL sources themselves can be compiled by javac when building LWJGL itself, it can be inferred that there must be some import statement leading to where that @Nullable might come from. And in fact, every compilation unit has such an import: import javax.annotation.*;
So it is javax.annotation.Nullable, which was specified in JSR 305 and is available e.g. via https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305/3.0.2

iamcreasy

Quote from: KaiHH on May 27, 2018, 05:37:58And in fact, every compilation unit has such an import: import javax.annotation.*;

Yes, you are right, those source files have import javax.annotation.*; in their import. I wonder why the IDE is complaining about it...since it was marked as an error, I assumed the import wasn't there.

KaiHH

I just mentioned this for you to know which @Nullable was meant.
The IDE is now flagging this as an error because it cannot resolve the import, since by default there is no jsr-305 implementation on the classpath. You have to put this on the classpath (e.g. by downloading it from the site I mentioned) in order for the IDE to be happy.