inspection descriptions update related to Java 18 nest-mates (IDEA-283315)

GitOrigin-RevId: e9889020d1869b8df8e20212b7848737335ff2a4
This commit is contained in:
Bas Leijdekkers
2024-04-11 09:51:35 +00:00
committed by intellij-monorepo-bot
parent fab3cba2c3
commit 7bb2aefd05
3 changed files with 6 additions and 5 deletions
@@ -7,8 +7,8 @@ A <code>static</code> inner class does not keep an implicit reference to its enc
This prevents a common cause of memory leaks and uses less memory per class instance.
</p>
<p>
Since Java 18, only serializable anonymous classes keep an implicit reference to its enclosing instance,
if this reference is not used. So, if module language level is Java 18 or higher,
Since Java 18, only serializable anonymous classes keep an implicit reference to their enclosing instance,
if this reference is not used. Therefore, when the module language level is Java 18 or higher,
this inspection reports serializable classes only.
</p>
<p>The quick-fix extracts the anonymous class into a named <code>static</code> inner class.</p>
@@ -1,12 +1,12 @@
<html>
<body>
Reports <a href="https://www.c2.com/cgi/wiki?DoubleBraceInitialization">Double Brace Initialization</a>.
<p>Double brace initialization may cause memory leaks when used in a non-static context because it creates an anonymous class
that will reference the surrounding object.</p>
<p>Compared to regular initialization, double brace initialization provides worse performance since it requires loading an
additional class.</p>
<p>It may also cause failure of <code>equals()</code> comparisons if the <code>equals()</code> method doesn't accept subclasses as
parameters.</p>
<p>Double brace initialization may cause memory leaks when used in a non-static context. This is because it defines an anonymous class
that will reference the surrounding object, when compiled with javac from before Java 18.</p>
<p>In addition, before Java 9, double brace initialization couldn't be combined with the diamond operator since it was incompatible
with anonymous classes.
</p>
@@ -2,7 +2,8 @@
<body>
Reports inner classes that can be made <code>static</code>.
<p>A <code>static</code> inner class does not keep an implicit reference to its enclosing instance.
This prevents a common cause of memory leaks and uses less memory per instance of the class.</p>
When using Java 17 or before,
this prevents a common cause of memory leaks and uses less memory per instance of the class.</p>
<p><b>Example:</b></p>
<pre><code>
<b>public class</b> Outer {