langtools/test/tools/javac/QualifiedAccess/QualifiedAccess_2.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 10 06bc494ca11e
child 863 3113c955a388
permissions -rw-r--r--
Initial load
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
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * @run shell QualifiedAccess_2.sh
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
import pack1.P1;
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
class A {
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
    private static class B {
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
        static class Inner {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
class X extends pack1.P1 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
    X() { super("bar"); }
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
    void foo() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
        /*-----------------*
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
        // BOGUS: Reports matching constructor not found.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
        // OK if 'Q' is made a public constructor.
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
        Object y = new Q("foo");// ERROR - protected constructor Q inaccessible
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
        *------------------*/
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
        // Reports 'P1.R.S' not found at all. (private)
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
        Object z = new R.S.T();         // ERROR - S is inaccessible
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
class Y {
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
    class Foo {
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
        class Bar {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
    class C extends A.B {}              // ERROR - B is inaccessible
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
    class D extends A.B.Inner {}        // ERROR - B is inaccessible
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
    static class Quux {
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
        private static class Quem {
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
            P1.Foo.Bar x;               // ERROR - Foo is inaccessible
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
            static class MyError extends Error {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
}
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
class Z {
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    void foo() throws Y.Quux.Quem.MyError {
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
                                // ERROR - type of Quux not accesible (private)
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
        throw new 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
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
}