mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-29 07:03:37 +07:00
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
25 lines
1.0 KiB
HTML
25 lines
1.0 KiB
HTML
<html>
|
|
<body>
|
|
Reports <code>Runnable</code> passed to a <code>Cleaner.register()</code> capturing reference being registered.
|
|
If the reference is captured, it will never be phantom reachable and the cleaning action will never be invoked.
|
|
<p>Possible sources of this problem:</p>
|
|
<ul>
|
|
<li>Lambda using non-static methods, fields, or <code>this</code> itself</li>
|
|
<li>Non-static inner class (anonymous or not) always captures this reference in java up to 18 version</li>
|
|
<li>Instance method reference</li>
|
|
<li>Access to outer class non-static members from non-static inner class</li>
|
|
</ul>
|
|
<!-- tooltip end -->
|
|
<p>Sample of code that will be reported: </p>
|
|
<pre><code>
|
|
int fileDescriptor;
|
|
Cleaner.Cleanable cleanable = Cleaner.create().register(this, () -> {
|
|
System.out.println("adsad");
|
|
//<i>this</i> is captured via <i>fileDescriptor</i>
|
|
fileDescriptor = 0;
|
|
});
|
|
</code></pre>
|
|
<p>This inspection only reports if the language level of the project or module is 9 or higher.</p>
|
|
<p><small>New in 2018.1</small></p>
|
|
</body>
|
|
</html> |