langtools/test/tools/javac/QualifiedAccess/QualifiedAccess_2.java
author sogoel
Thu, 05 Jun 2014 10:57:10 -0700
changeset 24797 850ebd4d80a7
parent 6150 d055fa8ced62
permissions -rw-r--r--
8044072: Group 2: create .out files for OverrideChecks tests in tools/javac dir Reviewed-by: jjg
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/**
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * @test  /nodynamiccopyright/
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * @bug 4094658 4277300 4785453
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 * @summary Test enforcement of JLS 6.6.1 and 6.6.2 rules requiring that
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * the type to which a component member belongs be accessible in qualified
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * names.
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 *
863
3113c955a388 6724327: eliminate use of shell tests for simple golden file tests
jjg
parents: 10
diff changeset
     8
 * @compile pack1/P1.java
3113c955a388 6724327: eliminate use of shell tests for simple golden file tests
jjg
parents: 10
diff changeset
     9
 * @compile pack1/P2.java
6150
d055fa8ced62 6971882: Remove -XDstdout from javac test
jjg
parents: 863
diff changeset
    10
 * @compile/fail/ref=QualifiedAccess_2.out -XDrawDiagnostics QualifiedAccess_2.java
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
import pack1.P1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
class A {
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
    private static class B {
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
        static class Inner {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
class X extends pack1.P1 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
    X() { super("bar"); }
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
    void foo() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
        /*-----------------*
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
        // BOGUS: Reports matching constructor not found.
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
        // OK if 'Q' is made a public constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
        Object y = new Q("foo");// ERROR - protected constructor Q inaccessible
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
        *------------------*/
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
        // Reports 'P1.R.S' not found at all. (private)
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
        Object z = new R.S.T();         // ERROR - S is inaccessible
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
class Y {
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
    class Foo {
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
        class Bar {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
    class C extends A.B {}              // ERROR - B is inaccessible
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
    class D extends A.B.Inner {}        // ERROR - B is inaccessible
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    static class Quux {
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
        private static class Quem {
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
            P1.Foo.Bar x;               // ERROR - Foo is inaccessible
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
            static class MyError extends Error {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
class Z {
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    void foo() throws Y.Quux.Quem.MyError {
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
                                // ERROR - type of Quux not accesible (private)
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
        throw new Y.Quux.Quem.MyError();
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
                                // ERROR - type of Quux not accesible (private)
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
}