Skip to content

Add @EnsuresInitialized postcondition to the Initialization Checker - #1918

Merged
wmdietl merged 19 commits into
eisop:masterfrom
aosen-xiong:feature/ensures-initialized
Aug 31, 2026
Merged

Add @EnsuresInitialized postcondition to the Initialization Checker#1918
wmdietl merged 19 commits into
eisop:masterfrom
aosen-xiong:feature/ensures-initialized

Conversation

@aosen-xiong

Copy link
Copy Markdown
Collaborator

This PR introduces the @EnsuresInitialized postcondition annotation to the Initialization Checker, resolving a
long-standing TODO in the manual.

The mutability checker will also use this to fix this test case.

Merge with eisop/jdk#136.

Copilot AI lite review requested due to automatic review settings August 5, 2026 07:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 @EnsuresInitialized as a repeatable postcondition annotation in checker-qual.
  • Updates the Nullness Checker manual to recommend @EnsuresInitialized for primitive fields.
  • Adds a regression test exercising satisfied and unsatisfied @EnsuresInitialized postconditions 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-arguments tag in the value() 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.

aosen-xiong and others added 6 commits August 5, 2026 03:09
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.
@wmdietl

wmdietl commented Aug 27, 2026

Copy link
Copy Markdown
Member

@aosen-xiong Please look through my last commit and see whether you agree. Also see the follow-up issue #1982 .

@wmdietl wmdietl assigned aosen-xiong and unassigned wmdietl Aug 27, 2026
@wmdietl wmdietl changed the title Add @EnsuresInitialized postcondition to Initialization Checker Add @EnsuresInitialized postcondition to the Initialization Checker Aug 27, 2026
wmdietl and others added 2 commits August 27, 2026 19:15
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.
aosen-xiong added a commit to aosen-xiong/jdk that referenced this pull request Aug 28, 2026
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.
@aosen-xiong aosen-xiong assigned wmdietl and unassigned aosen-xiong Aug 28, 2026
@wmdietl

wmdietl commented Aug 30, 2026

Copy link
Copy Markdown
Member

CI was failing when I committed. Then I remembered eisop-plume-lib/plume-scripts#14 and merged it. Now it passes!

@wmdietl
wmdietl merged commit aaa0185 into eisop:master Aug 31, 2026
44 checks passed
@aosen-xiong
aosen-xiong deleted the feature/ensures-initialized branch August 31, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants