langtools/test/tools/javac/QualifiedAccess/QualifiedAccess_3.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 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
 *
6150
d055fa8ced62 6971882: Remove -XDstdout from javac test
jjg
parents: 863
diff changeset
     8
 * @compile/fail/ref=QualifiedAccess_3.out -XDrawDiagnostics QualifiedAccess_3.java
10
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 CMain {
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
    class Foo {
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
        class Bar {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
    static class Baz {
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
        private static class Quux {
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
            static class Quem {}
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
    // These are all OK.
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
    CMain z = new CMain();
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
    Foo x = z.new Foo();
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
    Foo.Bar y = x.new Bar();
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
    void test() {
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
        P1 p1 = new P1();
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
        // These are NOT errors, and should NOT be detected, as observed.
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
        /*------------------------------------*
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
        Baz.Quux z = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
        Baz.Quux.Quem y = null;
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
        *------------------------------------*/
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
        P1.Foo.Bar x = null;            // ERROR - 'P1.Foo' not accessible
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
        int i = p1.a.length;            // ERROR - Type of 'a' not accessible
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
        // The type of the expression from which a component
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
        // is selected must be accessible.
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
        p1.p2.privatei = 3;             // ERROR - Type of 'p1.p2' not accessible.
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
        System.out.println (p1.p2.privatei);    // ERROR - Type of 'p1.p2' not accessible.
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
}