The Java Annotation Checker (JACK)

Introduction

JACK is a prototype tool for checking Java annotations. Currently, it supports only @NonNull annotations, although we plan to extend this to others (e.g. @ReadOnly, @Secure) in the future. The tool uses type inference technology (specifically, flow-sensitive dataflow analysis) in order to infer the affect of conditional statements on variable types. The tool assumes method parameters, return types and fields are already annotated appropriately. With this information, it checks method bodies for "type errors". For example, consider the following program:

The first error indicates that the toString method must return a @NonNull value. The second says that we can't invoke a method on a value which is not known to be @NonNull. Now, we can try and fix this by adding @NonNull annotations appropriately:

Here, we have used the @NonNull annotation to state that aField can never hold the null value. Likewise we must also annotate the parameter for set, otherwise jack would report an error. This time, running jack gives the following: