You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm writing java-only code, and I want it to be friendly to Kotlin users. I also would like the same Kotlin non-null semantics in Java, as much as possible.
I would like to apply [SpotBugs, Checker Framework, whatever], and have it yell at me if I'm assigning null to a field or variable anywhere that wasn't annotated as @OrNull.
I agree it would be very useful to have a simple and universal way of enforcing the nullability contract at compile-time.
I haven't truly explored this area so far, but I gave it a cursory look right now, and here's what I found...
SpotBugs
I wasn't able to find out in the docs if SpotBugs honors custom JSR-305-based nullability annotations (i.e. @NonNullPackage and @NullOr). Perhaps it can handle them out of the box like IntelliJ and Kotlin compiler (especially since SpotBugs is a successor of FindBugs, which relied on JSR-305). I guess you'd need to run SpotBugs and verify this.
Theoretically, one could also implement a custom SpotBugs plugin for it, but it'd seem an overkill to me.
However, I wasn't able to find out in the docs if it also supports meta JSR-305 annotations (@TypeQualifierDefault or @TypeQualifierNickname, which I used to define my annotations). So again, I guess you'd need to try it out.
IDEA Inspection Plugin
If you're using Gradle, one option that might work as expected (although I haven't tried it) could be IntelliJ IDEA inspection plugin (still in the "incubator", though). Since IntelliJ honors my annotations out of the box, simply turning on some nullable inspections should suffice.
I'm writing java-only code, and I want it to be friendly to Kotlin users. I also would like the same Kotlin non-null semantics in Java, as much as possible.
I would like to apply [SpotBugs, Checker Framework, whatever], and have it yell at me if I'm assigning null to a field or variable anywhere that wasn't annotated as
@OrNull
.Do you have any experience / recommendations for using your annotations with other tools? I really enjoyed your https://dzone.com/articles/when-to-use-jsr-305-for-nullability-in-java article, thanks for digging in and sorting through the various efforts!
The text was updated successfully, but these errors were encountered: