10
|
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 |
* @run shell QualifiedAccess_3.sh
|
|
9 |
*/
|
|
10 |
|
|
11 |
import pack1.P1;
|
|
12 |
|
|
13 |
class CMain {
|
|
14 |
|
|
15 |
class Foo {
|
|
16 |
class Bar {}
|
|
17 |
}
|
|
18 |
|
|
19 |
static class Baz {
|
|
20 |
private static class Quux {
|
|
21 |
static class Quem {}
|
|
22 |
}
|
|
23 |
}
|
|
24 |
|
|
25 |
// These are all OK.
|
|
26 |
CMain z = new CMain();
|
|
27 |
Foo x = z.new Foo();
|
|
28 |
Foo.Bar y = x.new Bar();
|
|
29 |
|
|
30 |
void test() {
|
|
31 |
P1 p1 = new P1();
|
|
32 |
|
|
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 |
*------------------------------------*/
|
|
38 |
|
|
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 |
}
|
|
46 |
|
|
47 |
}
|