<div dir="ltr"><div>Hi Remi,</div><div><br></div><div>You got me curious.... it turns out it's not hard to fix those cases as well as do a few other minor improvements.<br></div><div><br></div><div>I've created <a href="https://bugs.openjdk.org/browse/JDK-8317376" target="_blank">JDK-8317376</a> to track this.</div><div><br></div><div>-Archie<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 2, 2023 at 12:30 PM Archie Cobbs <<a href="mailto:archie.cobbs@gmail.com" target="_blank">archie.cobbs@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">Hi Remi,<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 2, 2023 at 2:18 AM Remi Forax <<a href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The compiler does not emit a warning when the access to "this" is buried inside an anonymous class<br></blockquote><div><br></div><div>This is a known limitation. In summary, the analyzer tracks 'this' references that are outer instance references from the current instance, but it doesn't track 'this' references that are outer instance references from arbitrary objects on the stack.</div><br><div>So when you say "new Inner()", the analyzer doesn't track the fact that the object on top of the stack now has a 'this' reference via its outer instance.</div><div><div><br></div><div>This is one of the (many) trade-offs that were made between precision vs. code complexity.<br></div><div><br></div></div><div>There are a couple of possible ways to address this:</div><div><ol><li>Using existing reference types: record "new Inner()" as having an indirect 'this' reference, and then update the logic for "Outer.this" to pessimistically assume any indirect reference is an outer reference. <br></li><li>Add a new reference type: OuterExprRef to mean "a 'this' reference from the outer instance of the object on the stack" and add tracking for it<br></li></ol></div><div>Option #1 would probably lead to a bunch of new false positives. Option #2 is more precise and therefore better but requires more code.<br></div><div><br></div><div>-Archie<br></div><div><br></div></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div></div>
</blockquote></div><br clear="all"><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div>