My java method can return null
and non null results. I want mark method with @Nullable
annotation to make it more readable.
I used com.sun.istack.internal.Nullable
but sonar says Classes from "sun.*" packages should not be used. Code smell Major squid:S1191.
I try to find more similar annotations, but there are variants from different IDE, not from java vendor.
Does java (oracle) provides alternatives for nullable annotation or I should use third party libraries only? If I have to use third party library to have an @Nullable
which one should be good?
Well, I think for Sonar you could use edu.umd.cs.findbugs.annotations.*, which are deprecated and advise you to use javax.annotation.Nullable.
I mainly use the Jetbrains ones, https://www.jetbrains.com/help/idea/nullable-and-notnull-annotations.html, but my main goal is the analysis in IntelliJ.
If you can, consider using Optional<T>
as the return type to make it more readable. You can express optionality utilizing the type system and benefit from the rich monadic-like API instead of wondering which annotation is the right one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With