#ref()
-Reports references to non-constant private members of an outer class from inside an inner class or
-to members of an inner class from a containing class.
+Reports references to non-constant private members of a different class,
+for which javac will generate a package-private synthetic accessor method.
An inner class and its containing class are compiled to separate
-class files. The virtual machine normally prohibits access from a class to private fields and methods of
+class files. The Java virtual machine normally prohibits access from a class to private fields and methods of
another class. To enable access from an inner class to private members of a
-containing class or the other way around javac and other compilers create package private
-synthetic accessor methods. Less use of memory and greater performance may be achieved by making the
-member package-private, thus allowing direct access without the creation of synthetic accessor methods.
+containing class or the other way around javac creates a package-private
+synthetic accessor method. Less use of memory and greater performance may be achieved by making the
+member package-private, thus allowing direct access without the creation of a synthetic accessor method.
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/j2me/private_member_access_between_outer_and_inner_class/PrivateMemberAccessBetweenOuterAndInnerClass.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/j2me/private_member_access_between_outer_and_inner_class/PrivateMemberAccessBetweenOuterAndInnerClass.java
index 3bd39cee153c..c5ebc18b6e00 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/j2me/private_member_access_between_outer_and_inner_class/PrivateMemberAccessBetweenOuterAndInnerClass.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/j2me/private_member_access_between_outer_and_inner_class/PrivateMemberAccessBetweenOuterAndInnerClass.java
@@ -9,7 +9,7 @@ public class PrivateMemberAccessBetweenOuterAndInnerClass {
System.out.println(caption);
Object btn = new Object() {
public void foo() {
- System.out.println(caption );
+ System.out.println(caption );
System.out.println(N);
}
};
@@ -17,3 +17,44 @@ public class PrivateMemberAccessBetweenOuterAndInnerClass {
private static class Inner{}
}
+class X {
+ void test() {
+ Private ref = new Private("access");
+ System.out.println(ref.field );
+ PrivateAccessor.printPrivate(ref);
+ new PrivateAccessor().print(ref);
+ }
+
+ private static class Private {
+ private final String field;
+ Private(String value) {
+ this.field = value;
+ }
+ }
+
+ private static class PrivateAccessor {
+ PrivateAccessor() {
+ // prevent synthetic constructor
+ }
+ void print(Private ref) {
+ System.out.println(ref.field );
+ }
+ static void printPrivate(Private ref) {
+ System.out.println(ref.field );
+ }
+ }
+}
+class Y {
+ void m() {
+ String caption = new PrivateMemberAccessBetweenOuterAndInnerClass().caption ;
+ //noinspection PrivateMemberAccessBetweenOuterAndInnerClass
+ System.out.println(X.s);
+
+ //noinspection SyntheticMethodCall
+ System.out.println(X.s);
+ }
+
+ static class X {
+ private static String s = "";
+ }
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/j2me/private_member_access_between_outer_and_inner_class/Simple.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/j2me/private_member_access_between_outer_and_inner_class/Simple.java
index 72143f8acf86..428dcb93c3b2 100644
--- a/plugins/InspectionGadgets/test/com/siyeh/igtest/j2me/private_member_access_between_outer_and_inner_class/Simple.java
+++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/j2me/private_member_access_between_outer_and_inner_class/Simple.java
@@ -9,9 +9,9 @@ public class Simple {
private void foo() {}
class Inner {{
- new Simple ();
- System.out.println(i );
- foo ();
+ new Simple ();
+ System.out.println(i );
+ foo ();
}}
}
class Other {