typetools / typetools/checker-framework

Suppress RLC warnings for safe first-time non-final field overwrites in constructors

Open
#7,049 0 comments 0 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.