This page walks you through a simple example to show how to use a type-checker in the Eclipse plugin. It shows how the Nullness Checker can be used to prevent null pointer exceptions.
public class NullnessExample { public static void main(String[] args) { Object myObject = null; System.out.println(myObject.toString()); } }
Run the Nullness Checker to see how it can warn you about this error at compile time. The Checker Framework Eclipse plugin documentation tells you how to run a checker and where the warnings appear.
The following warning will be produced.
dereference of possibly-null reference myObject System.out.println(myObject.toString());
Edit the code to initialize the myObject
variable
to some non-null value.
public class NullnessExample { public static void main(String[] args) { Object myObject = new Object(); System.out.println(myObject.toString()); } }
No errors should be produced.
This was a very simple example to show how to use the Checker Framework in Eclipse. The next example is a little more complex.