test/tools/javac/QualifiedAccess/QualifiedAccess_1.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /**
aoqi@0 2 * @test /nodynamiccopyright/
aoqi@0 3 * @bug 4094658 4277296 4785453
aoqi@0 4 * @summary Test enforcement of JLS 6.6.1 and 6.6.2 rules requiring that
aoqi@0 5 * the type to which a component member belongs be accessible in qualified
aoqi@0 6 * names.
aoqi@0 7 *
aoqi@0 8 * @compile pack1/P1.java
aoqi@0 9 * @compile pack1/P2.java
aoqi@0 10 * @compile/fail/ref=QualifiedAccess_1.out -XDrawDiagnostics QualifiedAccess_1.java
aoqi@0 11 */
aoqi@0 12
aoqi@0 13 import pack1.P1;
aoqi@0 14
aoqi@0 15 public class QualifiedAccess_1 {
aoqi@0 16
aoqi@0 17 // Inaccessible types in member declarations.
aoqi@0 18 // These exercise 'Env.resolve'.
aoqi@0 19 // Errors are localized poorly.
aoqi@0 20 //
aoqi@0 21 // Fields 'P3' and 'P5' are inaccessible.
aoqi@0 22
aoqi@0 23 P1 foo;
aoqi@0 24 P1.P3 bar; // ERROR
aoqi@0 25 P1.P3.P4 baz; // ERROR
aoqi@0 26 P1.P3.P4.P5 quux; // ERROR
aoqi@0 27
aoqi@0 28 P1 m11() {return null;}
aoqi@0 29 P1.P3 m12() {return null;} // ERROR
aoqi@0 30 P1.P3.P4 m13() {return null;} // ERROR
aoqi@0 31 P1.P3.P4.P5 m14() {return null;} // ERROR
aoqi@0 32
aoqi@0 33 void m21(P1 x) {}
aoqi@0 34 void m22(P1.P3 x) {} // ERROR
aoqi@0 35 void m23(P1.P3.P4 x) {} // ERROR
aoqi@0 36 void m24(P1.P3.P4.P5 x) {} // ERROR
aoqi@0 37
aoqi@0 38 void test1() {
aoqi@0 39
aoqi@0 40 // Inaccessible types in local variable declarations.
aoqi@0 41 // These exercise 'FieldExpression.checkCommon'.
aoqi@0 42 //
aoqi@0 43 // Fields 'P3' and 'P5' are inaccessible.
aoqi@0 44
aoqi@0 45 P1 foo = null;
aoqi@0 46 P1.P3 bar = null; // ERROR
aoqi@0 47 P1.P3.P4 baz = null; // ERROR
aoqi@0 48 P1.P3.P4.P5 quux = null; // ERROR
aoqi@0 49 }
aoqi@0 50
aoqi@0 51 void test2() {
aoqi@0 52
aoqi@0 53 // Inaccessible types in casts.
aoqi@0 54 // These exercise 'FieldExpression.checkCommon'.
aoqi@0 55 //
aoqi@0 56 // Fields 'P3' and 'P5' are inaccessible.
aoqi@0 57
aoqi@0 58 Object foo = (P1)null;
aoqi@0 59 Object bar = (P1.P3)null; // ERROR
aoqi@0 60 Object baz = (P1.P3.P4)null; // ERROR
aoqi@0 61 Object quux = (P1.P3.P4.P5)null; // ERROR
aoqi@0 62 }
aoqi@0 63
aoqi@0 64 void test3() {
aoqi@0 65
aoqi@0 66 // Inaccessible types in 'instanceof' expressions.
aoqi@0 67 // These exercise 'FieldExpression.checkCommon'.
aoqi@0 68 //
aoqi@0 69 // Fields 'P3' and 'P5' are inaccessible.
aoqi@0 70
aoqi@0 71 boolean foo = null instanceof P1;
aoqi@0 72 boolean bar = null instanceof P1.P3; // ERROR
aoqi@0 73 boolean baz = null instanceof P1.P3.P4; // ERROR
aoqi@0 74 boolean quux = null instanceof P1.P3.P4.P5; // ERROR
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 }

mercurial