0

I have configured Eclipse as seen in the screenshot. enter image description here

However I get no errors for this code:

  @Nonnull public static Object test(@CheckForNull Object t) {
    return t;
  }

When I run spotbugs on this code I get:

t must be non-null but is marked as nullable

How to get Eclipse to work with those annotations?

Version is: Eclipse IDE for Java Developers Version: 2020-03 (4.15.0)

NB. not sure if it's relevant but I'm using eclipse with the lombok plugin

Jakub Bochenski
  • 3,113
  • 4
  • 33
  • 61
  • Did you add and use the spotbugs eclipse plugin? Because eclipse own its own does not recognize jsr-305. (which is dead by the way). And I am curious in which section did you configure those settings? **Update** Interesting ...I found it in the compiler\Errors/warnings section. I would say you need to add the jsr-305.jar to the eclipse classpath so that the annotations are available for eclipse... – Lonzak Aug 20 '20 at 16:34

1 Answers1

0

You have configured it correctly. You have to add the JSR-305.jar dependency to your project to make it work. But you must have done that already since the imports are correctly resolved, right? I have created a testproject and correctly see an error:

Showing eclipse null error

If I remove the @Nonnull annotation the error goes away:

Everything is fine

Some infos can be found here.

Lonzak
  • 9,334
  • 5
  • 57
  • 88
  • Can you share you Eclipse version details (platform and jdt)? Did you configure it in any special way? – Jakub Bochenski Aug 20 '20 at 23:50
  • @JakubBochenski I did the configuration like you did in your screenshot. My eclipse version is 2019-12 (4.14.0) and Eclipse IDE for Enterprise Java Developers. – Lonzak Aug 21 '20 at 06:54
  • I have a slightly more recent version and I'm using a different base distribution. Not a big chance but maybe it matters – Jakub Bochenski Aug 21 '20 at 10:14