Skip to content

Suppresses RLC non-final field overwrite warning for safe constructor field initialization#7050

Open
iamsanjaymalakar wants to merge 114 commits intotypetools:masterfrom
iamsanjaymalakar:7049-dev
Open

Suppresses RLC non-final field overwrite warning for safe constructor field initialization#7050
iamsanjaymalakar wants to merge 114 commits intotypetools:masterfrom
iamsanjaymalakar:7049-dev

Conversation

@iamsanjaymalakar
Copy link
Copy Markdown
Member

@iamsanjaymalakar iamsanjaymalakar commented Apr 18, 2025

Summary by CodeRabbit

  • New Features

    • Enhanced resource leak checker to suppress false-positive warnings when a private field is assigned for the first time within a constructor.
  • Tests

    • Added comprehensive test suite covering various constructor initialization scenarios, including inline initializers, instance initializers, method calls, and conditional branching.

@iamsanjaymalakar iamsanjaymalakar self-assigned this Apr 18, 2025
Copy link
Copy Markdown
Contributor

@kelloggm kelloggm left a comment

Choose a reason for hiding this comment

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

Overall looks good, just a few minor comments. I'd like to take one more look before we merge, though.

@mernst mernst changed the title Suppresses RLC non-final field overwrite warning for safe constructor… #7049 Suppresses RLC non-final field overwrite warning for safe constructor field initialization Apr 18, 2025
@mernst
Copy link
Copy Markdown
Member

mernst commented Apr 18, 2025

@iamsanjaymalakar The typecheck job is not passing.

kelloggm
kelloggm previously approved these changes Jun 6, 2025
Copy link
Copy Markdown
Contributor

@kelloggm kelloggm left a comment

Choose a reason for hiding this comment

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

LGTM, I don't need to review again. Please address these comments and then request a review from Mike.

@mernst
Copy link
Copy Markdown
Member

mernst commented Jul 10, 2025

@iamsanjaymalakar Martin asked you to assign me when you had addressed his comments. Have you addressed them?

@iamsanjaymalakar iamsanjaymalakar assigned mernst and unassigned kelloggm Jul 14, 2025
@iamsanjaymalakar
Copy link
Copy Markdown
Member Author

@iamsanjaymalakar Martin asked you to assign me when you had addressed his comments. Have you addressed them?

Yes, I have. You can take a look.

Copy link
Copy Markdown
Member

@mernst mernst left a comment

Choose a reason for hiding this comment

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

Please clarify some documentation, and update the code if necessary. (I didn't read the code because there is no point in doing so until the documentation is clear.)

@mernst mernst assigned iamsanjaymalakar and unassigned mernst Jul 14, 2025
Copy link
Copy Markdown
Member

@mernst mernst left a comment

Choose a reason for hiding this comment

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

Thanks! This is looking solid. I have a few comments and questions, and then after another round I hope this can be merged.

@mernst mernst assigned iamsanjaymalakar and unassigned mernst Apr 9, 2026

public FirstAssignmentInConditional(boolean b) {
try {
if (b) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see how it would turn into a CFG dependency.

try {
if (b) {
// ::error: (required.method.not.called)
s = new FileInputStream("test1.txt"); // false positive: first write in this branch
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see that handling branches requires control-flow reasoning or a control-flow graph. It can be done purely (and simply) in the AST. If you don't want to do it, that is one thing, but please provide the correct rationale.

I think the wording you are looking for is "lexically first"; "AST-only" does not convey anything to me.

@mernst
Copy link
Copy Markdown
Member

mernst commented Apr 14, 2026

@iamsanjaymalakar When you address a code review comment, please mark it as "resolved" so that we know its status and it does not clutter this code review webpage.

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.

5 participants