<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
There's a few things you could mean by "not worth bothering" here.
For things within a source file, we can detect when the use of
`this` is safe, as in:<br>
<br>
class Foo { <br>
Foo() { m(this); }<br>
private void m(Foo f) { /* nothing */ }<br>
}<br>
<br>
and so we could elide warnings for cases like this if we wanted to.
But in general, what I'm saying is that we should warn when we
detect there is a *possibility* of a problem, rather than having to
prove that there *will be* a problem. <br>
<br>
The HashMap example is really the kind of code that we want to give
users feedback on, because people make dodgy self-use from
constructors all the time, and don't realize they are setting a time
bomb. Similarly, people enqueue listeners from constructors, and if
the listener gets called too early ... boom. These are the things
we want to detect. The rest, like the above examples, is trimming
away false positives.<br>
<br>
<div class="moz-cite-prefix">On 11/9/2022 11:54 AM, Archie Cobbs
wrote:<br>
</div>
<blockquote type="cite" cite="mid:CANSoFxuyT6diowPQQa3yPkqhfgjTC6ZGnCa3J=450aaFik-MpQ@mail.gmail.com">
<div dir="ltr">
<div dir="ltr">On Wed, Nov 9, 2022 at 10:38 AM Brian Goetz <<a href="mailto:brian.goetz@oracle.com" target="_blank" moz-do-not-send="true" class="moz-txt-link-freetext">brian.goetz@oracle.com</a>>
wrote:<br>
</div>
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
<div> <br>
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_quote">Agreed... that formulation is
simpler. But of course it would need a caveat for
subclasses within the same compilation unit, e.g.:</div>
</div>
</blockquote>
<br>
All these classes are in the same compilation unit, though
it's possible you may not want to get fancy enough with
the analysis to simulate virtual dispatch (though you
could, since its all in the same file.) <br>
</div>
</blockquote>
<div><br>
</div>
<div>OK so it sounds like you're saying that it's not worth
bothering trying to prevent someone from a 'this' escape
that is contained within a single source file, because those
cases are relatively easy ones to spot.</div>
<br>
<div>Rather, it's in the non-obvious cases, where the problem
spans multiple compilation units, that programmers could
really benefit from some extra help from the compiler.<br>
</div>
<div>
<div><br>
</div>
<div>This defines a clear & straightforward boundary for
the warning.<br>
</div>
<div><br>
</div>
</div>
<div>-Archie<br>
</div>
</div>
</div>
</blockquote>
<br>
</body>
</html>