RFR: 8355753: @SuppressWarnings("this-escape") not respected for indirect leak via field

Archie Cobbs acobbs at openjdk.org
Mon Apr 28 17:12:59 UTC 2025


This PR corrects a bug in the logic for handling `@SuppressWarnings("this-escape")` when the leak is from a field initializer.

The `ThisEscapeAnalyzer` has to do some custom handling for `@SuppressWarnings("this-escape")` because when a constructor executes, the actual path of execution can jump around between multiple constructors, field initializers, and initialization blocks. The previous logic was somewhat ad hoc and contained at least one bug (this one), so this PR refactors it to fix the bug and also make the code clearer.

Now we "execute" field initializers and initialization blocks when we encounter `super()` invocations, just like the actual JVM does, and we move the logics for (a) applying suppression and (b) the "at most one warning per constructor or initializer" rule until after the analysis, so they are part of the existing warning filtering and de-duplication step.

-------------

Commit messages:
 - Refactor ThisEscapeAnalyzer to correct bug in suppression logic.

Changes: https://git.openjdk.org/jdk/pull/24932/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=24932&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8355753
  Stats: 376 lines in 2 files changed: 182 ins; 104 del; 90 mod
  Patch: https://git.openjdk.org/jdk/pull/24932.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/24932/head:pull/24932

PR: https://git.openjdk.org/jdk/pull/24932


More information about the compiler-dev mailing list