Add @EnsuresInitialized postcondition to the Initialization Checker - #1918
Conversation
There was a problem hiding this comment.
🟢 Ready to approve
The changes are small, additive, and include a targeted test; only minor Javadoc consistency nits were identified.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
This PR adds a new Initialization Checker postcondition annotation, @EnsuresInitialized, and updates documentation/tests so primitive fields can be handled via initialization postconditions (instead of relying on @EnsuresNonNull).
Changes:
- Introduces
@EnsuresInitializedas a repeatable postcondition annotation inchecker-qual. - Updates the Nullness Checker manual to recommend
@EnsuresInitializedfor primitive fields. - Adds a regression test exercising satisfied and unsatisfied
@EnsuresInitializedpostconditions on primitive fields.
File summaries
| File | Description |
|---|---|
| docs/manual/nullness-checker.tex | Replaces the prior TODO with guidance to use @EnsuresInitialized for primitive fields. |
| checker/tests/nullness-initialization/EnsuresInitializedPrimitive.java | New test validating correct diagnostics for satisfied/unsatisfied @EnsuresInitialized postconditions. |
| checker-qual/src/main/java/org/checkerframework/checker/initialization/qual/EnsuresInitialized.java | Adds the new @EnsuresInitialized postcondition annotation API in checker-qual. |
Review details
Suppressed comments (1)
checker-qual/src/main/java/org/checkerframework/checker/initialization/qual/EnsuresInitialized.java:35
- Other postcondition annotations whose
value()is a Java-expression string array include a@checker_framework.manual #java-expressions-as-argumentstag in thevalue()Javadoc (e.g.,EnsuresNonNull). Adding it here improves discoverability and keeps the documentation consistent.
/**
* The Java expressions that are initialized upon successful method termination.
*
* @return the Java expressions that are initialized
*/
String[] value();
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
Re-run CI now that the eisop/jdk copy of EnsuresInitialized.java has the same indentation as the checker-qual copy, which check-jdk-consistency.sh compares byte-for-byte.
Explain that EnsuresInitialized is for tracking field assignments during the UnderInitialization lifecycle phase, independent of nullness, and that using it on a fully Initialized receiver is redundant.
|
@aosen-xiong Please look through my last commit and see whether you agree. Also see the follow-up issue #1982 . |
@EnsuresInitialized postcondition to the Initialization Checker
Explain that EnsuresInitialized is for tracking field assignments during the UnderInitialization lifecycle phase, independent of nullness, and that using it on a fully Initialized receiver is redundant.
The previous run failed check-jdk-consistency.sh with "File missing in JDK: checker/initialization/qual/EnsuresInitialized.java". That run was pushed by a different user, so git-clone-related resolved CI_ORGANIZATION to that user's fork, found no matching jdk branch, and fell back to eisop/jdk master, which does not have the new qualifier. The companion branch aosen-xiong/jdk:feature/ensures-initialized has been updated with the Javadoc clarification, so re-running from this fork picks it up and the consistency check passes.
Picks up the Javadoc clarification added in eisop/checker-framework#1918: when the annotation is useful, that it is trivially true on an already @initialized receiver, and to prefer @EnsuresNonNull when a nullness guarantee is also wanted. check-jdk-consistency.sh requires this file to be identical to the checker-qual copy.
|
CI was failing when I committed. Then I remembered eisop-plume-lib/plume-scripts#14 and merged it. Now it passes! |
This PR introduces the
@EnsuresInitializedpostcondition annotation to the Initialization Checker, resolving along-standing TODO in the manual.
The mutability checker will also use this to fix this test case.
Merge with eisop/jdk#136.