<div dir="ltr"><div dir="ltr">On Wed, Jan 4, 2023 at 1:23 PM Brian Goetz <<a href="mailto:brian.goetz@oracle.com" target="_blank">brian.goetz@oracle.com</a>> wrote:</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>
<div>
<blockquote type="cite">
<div>
<div dir="ltr">
<div>
<div><br>
</div>for things like the ArrayList constructors that call add, this is fundamentally dangerous and probably wants a note.</div></div></div></blockquote></div></div></blockquote><div>Agreed... except ArrayList is a bad example :) ArrayList(Collection c) actually does not invoke <span style="font-family:monospace">add()</span> or <span style="font-family:monospace">addAll()</span>. Instead it invokes <span style="font-family:monospace">c.toArray()</span>.<br></div><div><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><div>
<blockquote type="cite">
<div dir="ltr">
<div class="gmail_quote">
<div><br>
</div>
<div>Also, since the last post I found and fixed a few bugs, which revealed more 'this' escapes. Here are the new numbers, which have gone up a bit:<br>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>Are there interesting examples of the new form that we didn’t detect before, that would be educational to share?</div></div>
</div>
</blockquote></div><br clear="all"><div class="gmail_quote"><div>Not really - the increase was just due to a dumb bug in which unqualified method invocations like "foo()" were not
always being caught.</div><div><br></div><div>In general though, from what I can tell, most leaks are pretty much what you might expect. Many of them fall into the bucket of "Yes this is a leak, but it's unlikely to cause trouble in practice." But there are definitely some "dangerous" ones too, such as <span style="font-family:monospace">HashSet</span>, etc.<br></div><div><br></div><div>The most common pattern for leaks is invoking some non-static method in the constructor.<span style="font-family:arial,sans-serif"> For example, lots of classes invoke some kind of <span style="font-family:monospace">init()</span> method or whatever. Basically the constructor needs to do some work, and for whatever reason (some part of) that work has been abstracted out into a separate method or lives in a superclass.<br><br></span></div><div>For example, lots of Swing widget construc<span style="font-family:arial,sans-serif">tors invoke methods like <span style="font-family:monospace">setLayout()</span>, <span style="font-family:monospace">setBackground()</span>, <span style="font-family:monospace">setBorder()</span>, etc.</span></div><div><br><span style="font-family:arial,sans-serif"></span></div><div><span style="font-family:arial,sans-serif">Several exception classes invoke <span style="font-family:monospace">initCause()<span style="font-family:arial,sans-serif"> (and of course Throwable is guilty of invoking <span style="font-family:monospace">fillInStackTrace()</span>, which is not final).</span></span><br></span></div><br><div><span style="font-family:arial,sans-serif">Several classes invoke <span style="font-family:monospace">CleanerFactory.cleaner().register(this, ...)</span>.<br></span></div><div><span style="font-family:arial,sans-serif"><br></span></div><div><span style="font-family:arial,sans-serif">In short this warning, like a lot of the other lint warnings, seems to fall into the category that you're likely to get false positives, but that's hopefully worth it in exchange for a new category of automated bug detection.<br></span></div><div><span style="font-family:arial,sans-serif"><br></span></div><div><span style="font-family:arial,sans-serif">What are the next steps?<br></span></div><div><span style="font-family:arial,sans-serif"><br></span></div><div><span style="font-family:arial,sans-serif">-Archie</span><br></div></div><br>-- <br><div dir="ltr">Archie L. Cobbs<br></div></div>