Wed, 12 Feb 2014 11:16:22 -0800
Added tag jdk8u11-b00 for changeset c9db8c800797
duke@1 | 1 | /** |
duke@1 | 2 | * @test /nodynamiccopyright/ |
duke@1 | 3 | * @bug 4094658 4785453 |
duke@1 | 4 | * @summary Test enforcement of JLS 6.6.1 and 6.6.2 rules requiring that |
duke@1 | 5 | * the type to which a component member belongs be accessible in qualified |
duke@1 | 6 | * names. |
duke@1 | 7 | * |
jjg@611 | 8 | * @compile/fail/ref=QualifiedAccess_3.out -XDrawDiagnostics QualifiedAccess_3.java |
duke@1 | 9 | */ |
duke@1 | 10 | |
duke@1 | 11 | import pack1.P1; |
duke@1 | 12 | |
duke@1 | 13 | class CMain { |
duke@1 | 14 | |
duke@1 | 15 | class Foo { |
duke@1 | 16 | class Bar {} |
duke@1 | 17 | } |
duke@1 | 18 | |
duke@1 | 19 | static class Baz { |
duke@1 | 20 | private static class Quux { |
duke@1 | 21 | static class Quem {} |
duke@1 | 22 | } |
duke@1 | 23 | } |
duke@1 | 24 | |
duke@1 | 25 | // These are all OK. |
duke@1 | 26 | CMain z = new CMain(); |
duke@1 | 27 | Foo x = z.new Foo(); |
duke@1 | 28 | Foo.Bar y = x.new Bar(); |
duke@1 | 29 | |
duke@1 | 30 | void test() { |
duke@1 | 31 | P1 p1 = new P1(); |
duke@1 | 32 | |
duke@1 | 33 | // These are NOT errors, and should NOT be detected, as observed. |
duke@1 | 34 | /*------------------------------------* |
duke@1 | 35 | Baz.Quux z = null; |
duke@1 | 36 | Baz.Quux.Quem y = null; |
duke@1 | 37 | *------------------------------------*/ |
duke@1 | 38 | |
duke@1 | 39 | P1.Foo.Bar x = null; // ERROR - 'P1.Foo' not accessible |
duke@1 | 40 | int i = p1.a.length; // ERROR - Type of 'a' not accessible |
duke@1 | 41 | // The type of the expression from which a component |
duke@1 | 42 | // is selected must be accessible. |
duke@1 | 43 | p1.p2.privatei = 3; // ERROR - Type of 'p1.p2' not accessible. |
duke@1 | 44 | System.out.println (p1.p2.privatei); // ERROR - Type of 'p1.p2' not accessible. |
duke@1 | 45 | } |
duke@1 | 46 | |
duke@1 | 47 | } |