16

In our open source constraint solver (OptaPlanner), I want to use @NonNull to make it more Kotlin friendly and clearer to use from Java, too.

spring-core already uses @NonNull, for example in this code. They effectively state for every method parameter if it's nullable or not, as explained here.

Which maven/gradle dependency should I use to have the class javax.annotation.Nonnull in my classpath? Which one do the spring guys use? For example, I don't see the findbugs JSR-305 jar in their dependency list.

(And can I have it as an optional dependency to avoid bloating my user's classpath?)

3
  • org.springframework.lang.NonNullApi Should be used at package level in association with org.springframework.lang.Nullable annotations at parameter and return value level. org.springframework.lang.Nullable Should be used at parameters, return values and optionally field level in association with NonNullApi package-level annotations. Commented Dec 19, 2018 at 1:30
  • I need a neutral jar. I am not going to drag in spring from optaplanner-core (only in optaplanner-spring-boot-starter which provides seamless integration) Commented Apr 28, 2020 at 8:04
  • The following answer suggests that JSR 305 is not the way to go, as it is "Dormant": stackoverflow.com/questions/2289694/… Commented Jul 3, 2020 at 11:08

1 Answer 1

7

I would say that https://mvnrepository.com/artifact/com.google.code.findbugs/jsr305 should be your artifact of choice for this, as it's probably the most commonly used and properly maintained.

Sign up to request clarification or add additional context in comments.

3 Comments

Looks like findbugs in dead, replaced by spotbugs (by the community), which decided to no longer include those annotations: github.com/spotbugs/spotbugs/pull/180
I would disagree that findbugs is properly maintained
I would like to have a guide to how to install it. What to download, where to put it, how to make it work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.