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

Vicente Romero vromero at openjdk.org
Fri May 30 03:31:56 UTC 2025


On Thu, 29 May 2025 21:25:38 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

>> 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.
>
> Archie Cobbs has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:
> 
>  - Add additional tests for warnings generated from fields.
>  - Merge branch 'master' into JDK-8355753
>  - Refactor ThisEscapeAnalyzer to correct bug in suppression logic.

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java line 1794:

> 1792:               IntStream.range(0, that.stack.size())
> 1793:                 .allMatch(index -> this.stack.get(numExtra + index).comparePos(that.stack.get(index)) == 0);
> 1794:         };

Suggestion:

        }

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java line 1814:

> 1812:                     return diff;
> 1813:             }
> 1814:         };

Suggestion:

        }

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24932#discussion_r2114679004
PR Review Comment: https://git.openjdk.org/jdk/pull/24932#discussion_r2114678422


More information about the compiler-dev mailing list