Enhancement #5666: enhancing report with adding Sarif Report(POC)
Summary
This PR introduces a proof-of-concept implementation of SARIF report generation for the Checker Framework. It enables checkers to produce SARIF 2.1.0–compliant JSON report files containing diagnostic messages and their corresponding source locations.
Unit tests are not included at this stage. I’d like to first align with contributors on the overall design before adding tests
Motivation
Related issue: https://github.com/typetools/checker-framework/issues/5666
How to Use SARIF
javac -processor NullnessChecker -AsarifOutput=report.sarif MyFile.java
This generates a report.sarif file containing all diagnostics in SARIF 2.1.0 format.
The report.sarif file would be like that:
{
"version" : "2.1.0",
"runs" : [ {
"tool" : {
"driver" : {
"name" : "Checker Framework",
"version" : "3.52.1-SNAPSHOT"
}
},
"results" : [ {
"ruleId" : "assignment",
"level" : "error",
"message" : {
"text" : "[assignment] incompatible types in assignment.\nfound : Set<@KeyFor(\"sharedCounts1\") String>\nrequired: Set<@KeyFor({\"sharedBooks\", \"sharedCounts1\"}) String>"
},
"locations" : [ {
"physicalLocation" : {
"artifactLocation" : {
"uri" : "file:///Users/gaoyan/workspace/gsoc/fork/checker-framework/checker/tests/nullness/KeyForMultiple.java"
},
"region" : {
"startLine" : 25,
"startColumn" : 73,
"endLine" : 25,
"endColumn" : 95
}
}
} ]
}, {
"ruleId" : "assignment",
"level" : "error",
"message" : {
"text" : "[assignment] incompatible types in assignment.\nfound : Set<@KeyFor(\"sharedCounts2\") String>\nrequired: Set<@KeyFor({\"sharedBooks\", \"sharedCounts2\"}) String>"
},
"locations" : [ {
"physicalLocation" : {
"artifactLocation" : {
"uri" : "file:///Users/gaoyan/workspace/gsoc/fork/checker-framework/checker/tests/nullness/KeyForMultiple.java"
},
"region" : {
"startLine" : 41,
"startColumn" : 73,
"endLine" : 41,
"endColumn" : 95
}
}
} ]
} ]
} ]
}
Implementation Details
Message Flow
-
The SARIF generator is initialized in the root checker’s initChecker() method to ensure a single instance per compilation.
-
printOrStoreMessage()retrieves the root checker’s generator and forwards diagnostic messages to it. -
At the end of processing,
typeProcessingOver()writes the collected results to the SARIF file.
Compound Checker Support
-
Only the root checker creates and owns the SARIF generator.
-
Subcheckers access the same instance via getRootChecker().
-
This ensures all diagnostics from compound checkers are included in a single unified SARIF report.
Future Work
This POC lays the foundation, and several enhancements can be implemented later:
- Support for NOTE and WARNING message types
- Rule metadata extraction: populate run.tool.driver.rules with richer rule descriptions from
messages.properties(currently only ruleId is included) - Additional SARIF features (code flows, fixes, etc.)
- Add a static webpage for rendering SARIF output
- Update the user manual
Backward Compatibility
The feature is fully backward compatible:
SARIF generation is opt-in via the -AsarifOutput option
Existing console output remains unchanged
No breaking API changes
Failures in SARIF generation do not impact compilation
The PR adds SARIF report generation to the Checker Framework. Two Gradle dependencies were added: com.fasterxml.jackson.core:jackson-databind:2.15.0 and com.contrastsecurity:java-sarif:2.0. A new 📝 Walkthrough
Walkthrough
SarifReportGenerator class builds SARIF 2.1.0 logs from diagnostics. SourceChecker gains a sarifOutput option, fields to track SARIF state, initialization and teardown to create and write the report, and wiring to send diagnostics (including a messageKey) to the SARIF generator. CheckerMessage now includes a messageKey field.
Pre-merge checks and finishing touches
✅ Passed checks (1 passed)
| Check name | Status | Explanation |
|---|---|---|
| Docstring Coverage | ✅ Passed | Docstring coverage is 81.25% which is sufficient. The required threshold is 80.00%. |
✨ Finishing touches
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
@Gaoyan1999 The title includes "proof of concept". Do you want feedback on this pull request, or not yet?
@Gaoyan1999 The title includes "proof of concept". Do you want feedback on this pull request, or not yet?
@mernst Yes, I’d appreciate feedback.
This is just a simple PoC for now — no tests and only the happy path. I’ve listed some potential follow-up work in the “Future work” section of the description.
At this stage, I’m mainly looking for feedback on the overall idea and whether it’s worth continuing and building this out further.