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

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


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

>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java line 387:
>> 
>>> 385:         // Sort warnings so redundant warnings immediately follow whatever they are redundant for, then remove them
>>> 386:         warningList.sort(Warning::sortByStackFrames);
>>> 387:         AtomicReference<Warning> previousRef = new AtomicReference<>();
>> 
>> just curious: why do we need to deal with AtomicReference here?
>
> Hi @vicente-romero-oracle, thanks for taking a look.
> 
> The reason for the `AtomicReference` is that this lamba needs to be stateful (it needs to remember the most recent previous `Warning` that was also retained, if any), so if it wants to remain a lambda (i.e., and not a more verbose inner class) that state needs to be declared outside the lamba, and therefore it must be effectively final, which means there must be an extra level of indirection, etc. I guess it's a verbosity vs. clarity trade-off.

right, would an array be less heavy? not beautiful either

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

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


More information about the compiler-dev mailing list