Skip to content

Fix FinalizePrivateFields breaking code with lambda reads in field initializers#862

Merged
timtebeek merged 1 commit intomainfrom
tim/issue-861
Apr 17, 2026
Merged

Fix FinalizePrivateFields breaking code with lambda reads in field initializers#862
timtebeek merged 1 commit intomainfrom
tim/issue-861

Conversation

@timtebeek
Copy link
Copy Markdown
Member

@timtebeek timtebeek commented Apr 16, 2026

Summary

Test plan

  • Added fieldReadByLambdaInInstanceFieldInitializer reproducing the issue's exact example
  • Added fieldReadByAnonymousClassInInstanceFieldInitializer covering anonymous class bodies
  • All existing FinalizePrivateFieldsTest cases continue to pass

…a lambda initializer

Skip private fields whose only assignment is in the constructor body when they
are read inside a lambda or anonymous class in an instance field initializer or
instance initializer block. Since initializers run before the constructor body,
finalizing such fields breaks javac's definite assignment analysis.

Fixes #861
@github-project-automation github-project-automation bot moved this from In Progress to Ready to Review in OpenRewrite Apr 17, 2026
@timtebeek timtebeek merged commit 78afc25 into main Apr 17, 2026
1 check passed
@timtebeek timtebeek deleted the tim/issue-861 branch April 17, 2026 13:04
@github-project-automation github-project-automation bot moved this from Ready to Review to Done in OpenRewrite Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

FinalizePrivateFields produces uncompilable code when field is captured by a lambda in an instance field initializer

2 participants