This project is under development to become the reference implementation for the JSpecify nullness specification (and later, its other specifications as well). The current goal we're working toward is conformance with version 0.3 of that spec, but it's not there yet.
Though it does check your references (to see if they're null), that's not the intended meaning!
This tool's purpose is to report nullness-related findings correctly according to the JSpecify standard for nullness annotation semantics.
But that's its only job. Notably, it is:
- not expected to have good performance characteristics
- not expected to have good usability characteristics
... and there is no intention to make it competitive in these ways. Of course real tools by our partner organizations will be better.
The EISOP project maintains a fork of the Checker Framework, and JSpecify conformance is one of its goals.
This tool is built on top of the EISOP Checker Framework. However, please view this relationship as implementation detail only. Building a reference checker from scratch would simply have been too difficult, so we needed to base it on some existing tool. The choice of which tool was made purely for expediency and is subject to change.
Building and running this tool depends on code from several other repositories, but these instructions will take care of that automatically.
These instructions might require workarounds or fail outright. Please file an issue if you have any trouble!
Set JAVA_HOME to a JDK 17 or later installation.
Make sure you have Apache Maven installed and in your PATH, or the demo script will fail:
mvn
Choose a name for a brand new directory that doesn't already exist. It may be convenient to set $root_dir to that absolute path:
root_dir=/absolute/pathname/for/fresh/new/directory
... because then you can paste the commands below exactly as they are.
Now get the code for this project, JSpecify's annotated JDK, and JSpecify itself, which the tests use.
Warning: If you clone this project under a different name, watch out, as the later steps assume it to be named exactly jspecify-reference-checker.
The build expects the annotated JDK in the sibling directory jdk; pass
-PjspecifyJdkHome=/path/to/jdk to use a clone elsewhere.
mkdir $root_dir cd $root_dir git clone https://github.com/jspecify/jspecify-reference-checker git clone --depth 1 https://github.com/jspecify/jdk git clone https://github.com/jspecify/jspecify cd jspecify-reference-checker
Now build it:
./gradlew assemble
Run the checker on the sample file:
cd $root_dir/jspecify-reference-checker ./demo SimpleSample.java
(If you haven't built the reference checker yet, this will build it the first time you run it.)
After that, you should see:
SimpleSample.java:7: error: [nullness] incompatible types in return.
return mightBeNull;
^
type of expression: Object?
method return type: Object
1 error
Note that the demo script is not complicated, and illustrates how you can enable checking for your own code as well.
To perform a minimal test, run:
cd $root_dir/jspecify-reference-checker ./gradlew test
To run the (incomplete) conformance test suite, check out the main branch of jspecify and run conformanceTests:
git -C $root_dir/jspecify checkout main cd $root_dir/jspecify-reference-checker ./gradlew conformanceTests --include-build ../jspecify
To run the (legacy) "samples" test suite, check out the samples-google-prototype-eisop branch of jspecify and run jspecifySamplesTest:
git -C $root_dir/jspecify checkout samples-google-prototype-eisop cd $root_dir/jspecify-reference-checker ./gradlew jspecifySamplesTest --include-build ../jspecify