Wed, 12 Feb 2014 11:16:22 -0800
Added tag jdk8u11-b00 for changeset c9db8c800797
1 /**
2 * @test /nodynamiccopyright/
3 * @bug 4094658 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 * @compile/fail/ref=QualifiedAccess_3.out -XDrawDiagnostics QualifiedAccess_3.java
9 */
11 import pack1.P1;
13 class CMain {
15 class Foo {
16 class Bar {}
17 }
19 static class Baz {
20 private static class Quux {
21 static class Quem {}
22 }
23 }
25 // These are all OK.
26 CMain z = new CMain();
27 Foo x = z.new Foo();
28 Foo.Bar y = x.new Bar();
30 void test() {
31 P1 p1 = new P1();
33 // These are NOT errors, and should NOT be detected, as observed.
34 /*------------------------------------*
35 Baz.Quux z = null;
36 Baz.Quux.Quem y = null;
37 *------------------------------------*/
39 P1.Foo.Bar x = null; // ERROR - 'P1.Foo' not accessible
40 int i = p1.a.length; // ERROR - Type of 'a' not accessible
41 // The type of the expression from which a component
42 // is selected must be accessible.
43 p1.p2.privatei = 3; // ERROR - Type of 'p1.p2' not accessible.
44 System.out.println (p1.p2.privatei); // ERROR - Type of 'p1.p2' not accessible.
45 }
47 }