Hello Guest

Question about Nullable annotation

  • 3 Replies
  • 500 Views
Question about Nullable annotation
« on: May 27, 2018, 00:32:33 »
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?

*

Offline KaiHH

  • ***
  • 161
Re: Question about Nullable annotation
« Reply #1 on: May 27, 2018, 05:37:58 »
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
« Last Edit: May 27, 2018, 05:41:27 by KaiHH »

Re: Question about Nullable annotation
« Reply #2 on: May 27, 2018, 21:44:18 »
And 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.
« Last Edit: May 27, 2018, 21:51:37 by iamcreasy »

*

Offline KaiHH

  • ***
  • 161
Re: Question about Nullable annotation
« Reply #3 on: May 28, 2018, 08:04:54 »
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.