private
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.
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.
By making the private
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.
This inspection does not report if the language level is set to Java 11 or higher because thanks to nest-based access control (JEP 181), accessor methods are not generated anymore.
Example:
class Outer {
private void x() {}
class Inner {
void y() {
x();
}
}
}
After the quick fix is applied:
class Outer {
void x() {}
class Inner {
void y() {
x();
}
}
}