typetools / typetools/checker-framework
Suppress RLC warnings for safe first-time non-final field overwrites in constructors
Open
@iamsanjaymalakar is already working on this.
Since Apr 18, 2025.
ResourceLeakChecker
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 440
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 134
Description
The Resource Leak Checker currently flags warnings for field assignments in constructors, even when the constructor is clearly performing the first and only write to that field. This results in false positives for common patterns.
A warning should be suppressed when all of the following are true:
- The field is private
- It has no non-null inline initializer
- It’s not assigned in any instance initializer block
- The constructor doesn't call another constructor using this(...)
- The assignment is directly in the constructor
- There are no method calls (other than super) or earlier assignments to the same field before this one in the constructor body
Based on the JLS:
- Field initializers and instance initializer blocks run first
- Then the superclass constructor
- Then the constructor body runs
So if a private field is only written in the constructor body (and no earlier initialization happened), that assignment is guaranteed to be the first one.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.