Repository navigation
Conversation
With flexible constructor bodies (JEP 513), statements may precede a this(...) call. constructorInvokesAnother only looked at the first statement, so such a constructor was checked as if it had to initialize every @nonnull field itself. Check all direct statements of the body. Fixes apache#2145 Assisted-by: Claude Code (claude-fable-5-2) Signed-off-by: Mist-wu <qbsdwu@gmail.com>
Author
|
@msridhar This is ready for review whenever you have time. The workflows are waiting for maintainer approval to run on this PR; could you approve them? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With flexible constructor bodies (JEP 513), statements may precede a
this(...)call.constructorInvokesAnotheronly looked at the first statement of the body, so a constructor with a prologue was checked as if it had to initialize every@NonNullfield itself, and reads of those fields after thethis(...)call were reported as reads before initialization.The method now checks every direct statement of the constructor body. javac only accepts an explicit constructor call as a direct statement of the body, so nested blocks are not searched.
Tests are in
jdk-recent-unit-testsbecause the syntax needs JDK 25:this(...)first, after one statement, after several statements with a field read afterwards, a prologue ending insuper()(still reported), and athis(...)call inside a local class (still reported for the enclosing constructor).Fixes #2145
Assisted-by: Claude Code (claude-fable-5-2)