Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static verification support #21

Open
nedtwigg opened this issue Dec 3, 2019 · 1 comment
Open

Static verification support #21

nedtwigg opened this issue Dec 3, 2019 · 1 comment

Comments

@nedtwigg
Copy link

nedtwigg commented Dec 3, 2019

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!

@tlinkowski
Copy link
Owner

Hi Ned, thanks for your kind words!

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.

Checker Framework

Checker Framework clearly supports non-meta JSR-305 annotations like @javax.annotation.Nonnull.

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.


Hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants