These are step-by-step instructions for setting up Checker Framework (CF) for a basic Java project in IntelliJ. This is based on my configuration:
In these instructions, I’ll show you how to enable CF’s We’ll enable CF’s nullness checking for a simple test program.
From the Welcome to IntelliJ IDEA window:
Replace the content of Main.java
with:
Make sure that this program compiles and runs using Ctrl+R
. It should output null
to the console.
From File menu:
org.checkerframework
and click the search buttonorg.checkerframework:checker:1.9.10
and click OK twice to add this to the projectorg.checkerframework
and click the search buttonorg.checkerframework:jdk8:1.9.10
and click OK twice to add this to the projectorg.checkerframework
and click the search buttonorg.checkerframework:checker-qual:1.9.10
and click OK twice to add this to the projectFrom the IntelliJ IDEA application menu:
-Xbootclasspath/p:$USER_HOME$/.m2/repository/org/checkerframework/jdk8/1.9.10/jdk8-1.9.10.jar
Cmd-F9
to rebuildYou should see the following error in the build output pane:
Error:(20, 33) java: [argument.type.incompatible] incompatible types in argument.
found : null
required: @Initialized @NonNull String
This tells us that passing null
to the constructor of Foo
is invalid. Fix this line to pass a non-null
string:
final Foo foo = new Foo("Hello world");
Then press Cmd-F9
again and the program should compile without error.
Content © 2024 Richard Cook. All rights reserved.