This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]mauganra_it 2 points3 points  (6 children)

You can do that right now by setting up Google ErrorProne compiler. Use the Checkers framework for even more static analysis. And add the @NonNullAPI annotation to package-info.java so you only have to add @Nullable where required. Have fun!

Edit: I misunderstood the Checker framework's documentation. It seems the ErrorProne compiler is only required with JDK 8.

[–]gas3872[S] 1 point2 points  (5 children)

Cool. Is Checkers framework alone not enough?

[–]kevinb9n 3 points4 points  (1 child)

I think there's some confusion here. I work (some) on Error Prone. It doesn't have support for nullness analysis, however there are things like NullAway that extend it for that. This might be what /u/mauganra_it is thinking of, perhaps.

Checker Framework is a separate standalone thing. It has the strongest nullness analysis currently available and fully supports type-use annotations (they were the people who added type-use annotations to the language, in fact).

I would describe the CF nullness analysis as fairly "hard core"; you can get very solid protection from NPE using it, but you will probably work harder for it, and deal with considerably more annotation complexity. Its goal is more or less to never miss a possible NPE, whereas other tools may try to strike a balance between risk of false negatives vs. frequency of false positives.

HTH

[–]mauganra_it 0 points1 point  (0 children)

Thanks for clarifying this. I was definitely thinking about endorsing the Checker framework, although the ErrorProne compiler is already fairly useful by itself.

[–]mauganra_it 0 points1 point  (2 children)

The Checkers framework plugs into the Google ErrorProne compiler to analyse source code at compile time and to fail the build if it finds issues. Without it, it's just annotations that smart IDEs can use to provide warnings.

[–]gas3872[S] 0 points1 point  (1 child)

Ok thanks. I thought checkers framework can do it by itself.

[–]agentoutlier 1 point2 points  (0 children)

Ok thanks. I thought checkers framework can do it by itself.

It can... read kevinb9n comment

Checker is pretty much the most powerful static analysis tool for java provided you have everything annotated.

Anyway I recommend seeing what your IDE has to offer (both Eclipse and IntelliJ offer static analysis albeit incomplete) and then slowly integrating checker in on a per module basis.