Files
openide/java/java-impl/resources/inspectionDescriptions/PrivateMemberAccessBetweenOuterAndInnerClass.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

48 lines
1.5 KiB
HTML

<html>
<body>
Reports references from a nested class to non-constant <code>private</code> members of an outer class.
For such references, javac will generate package-private synthetic accessor methods,
which may compromise the security because members appearing to be private will in fact be accessible from the entire package.
<p>
A nested class and its outer class are compiled to separate
class files. The Java virtual machine normally prohibits access from a class to private fields and methods of
another class. To enable access from a nested class to private members of an outer class, javac creates a package-private
synthetic accessor method.
</p>
<p>
By making the <code>private</code> member package-private instead, the actual accessibility is made explicit.
This also saves a little bit of memory, which may improve performance in resource constrained environments.
</p>
<p>
This inspection only reports if the language level of the project or module is 10 or lower.
Under Java 11 and higher accessor methods are not generated anymore,
because of nest-based access control (<a href="https://openjdk.org/jeps/181">JEP 181</a>).
</p>
<p><b>Example:</b></p>
<pre><code>
class Outer {
private void x() {}
class Inner {
void y() {
x();
}
}
}
</code></pre>
<p>After the quick fix is applied:</p>
<pre><code>
class Outer {
void x() {}
class Inner {
void y() {
x();
}
}
}
</code></pre>
<!-- tooltip end -->
</body>
</html>