Wed, 09 Apr 2008 11:19:15 -0700
Added tag jdk7-b25 for changeset 58039502942e
1 /**
2 * @test /nodynamiccopyright/
3 * @bug 4094658 4277296 4785453
4 * @summary Test enforcement of JLS 6.6.1 and 6.6.2 rules requiring that
5 * the type to which a component member belongs be accessible in qualified
6 * names.
7 *
8 * @run shell QualifiedAccess_1.sh
9 */
11 import pack1.P1;
13 public class QualifiedAccess_1 {
15 // Inaccessible types in member declarations.
16 // These exercise 'Env.resolve'.
17 // Errors are localized poorly.
18 //
19 // Fields 'P3' and 'P5' are inaccessible.
21 P1 foo;
22 P1.P3 bar; // ERROR
23 P1.P3.P4 baz; // ERROR
24 P1.P3.P4.P5 quux; // ERROR
26 P1 m11() {return null;}
27 P1.P3 m12() {return null;} // ERROR
28 P1.P3.P4 m13() {return null;} // ERROR
29 P1.P3.P4.P5 m14() {return null;} // ERROR
31 void m21(P1 x) {}
32 void m22(P1.P3 x) {} // ERROR
33 void m23(P1.P3.P4 x) {} // ERROR
34 void m24(P1.P3.P4.P5 x) {} // ERROR
36 void test1() {
38 // Inaccessible types in local variable declarations.
39 // These exercise 'FieldExpression.checkCommon'.
40 //
41 // Fields 'P3' and 'P5' are inaccessible.
43 P1 foo = null;
44 P1.P3 bar = null; // ERROR
45 P1.P3.P4 baz = null; // ERROR
46 P1.P3.P4.P5 quux = null; // ERROR
47 }
49 void test2() {
51 // Inaccessible types in casts.
52 // These exercise 'FieldExpression.checkCommon'.
53 //
54 // Fields 'P3' and 'P5' are inaccessible.
56 Object foo = (P1)null;
57 Object bar = (P1.P3)null; // ERROR
58 Object baz = (P1.P3.P4)null; // ERROR
59 Object quux = (P1.P3.P4.P5)null; // ERROR
60 }
62 void test3() {
64 // Inaccessible types in 'instanceof' expressions.
65 // These exercise 'FieldExpression.checkCommon'.
66 //
67 // Fields 'P3' and 'P5' are inaccessible.
69 boolean foo = null instanceof P1;
70 boolean bar = null instanceof P1.P3; // ERROR
71 boolean baz = null instanceof P1.P3.P4; // ERROR
72 boolean quux = null instanceof P1.P3.P4.P5; // ERROR
73 }
75 }