test/tools/javac/QualifiedAccess/QualifiedAccess_1.java

changeset 1
9a66ca7c79fa
child 69
82c7aa6fe50a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/QualifiedAccess/QualifiedAccess_1.java	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,75 @@
     1.4 +/**
     1.5 + * @test  /nodynamiccopyright/
     1.6 + * @bug 4094658 4277296 4785453
     1.7 + * @summary Test enforcement of JLS 6.6.1 and 6.6.2 rules requiring that
     1.8 + * the type to which a component member belongs be accessible in qualified
     1.9 + * names.
    1.10 + *
    1.11 + * @run shell QualifiedAccess_1.sh
    1.12 + */
    1.13 +
    1.14 +import pack1.P1;
    1.15 +
    1.16 +public class QualifiedAccess_1 {
    1.17 +
    1.18 +    // Inaccessible types in member declarations.
    1.19 +    // These exercise 'Env.resolve'.
    1.20 +    // Errors are localized poorly.
    1.21 +    //
    1.22 +    // Fields 'P3' and 'P5' are inaccessible.
    1.23 +
    1.24 +    P1 foo;
    1.25 +    P1.P3 bar;                                  // ERROR
    1.26 +    P1.P3.P4 baz;                               // ERROR
    1.27 +    P1.P3.P4.P5 quux;                           // ERROR
    1.28 +
    1.29 +    P1 m11() {return null;}
    1.30 +    P1.P3 m12() {return null;}                  // ERROR
    1.31 +    P1.P3.P4 m13() {return null;}               // ERROR
    1.32 +    P1.P3.P4.P5 m14() {return null;}            // ERROR
    1.33 +
    1.34 +    void m21(P1 x) {}
    1.35 +    void m22(P1.P3 x) {}                        // ERROR
    1.36 +    void m23(P1.P3.P4 x) {}                     // ERROR
    1.37 +    void m24(P1.P3.P4.P5 x) {}                  // ERROR
    1.38 +
    1.39 +    void test1() {
    1.40 +
    1.41 +        // Inaccessible types in local variable declarations.
    1.42 +        // These exercise 'FieldExpression.checkCommon'.
    1.43 +        //
    1.44 +        // Fields 'P3' and 'P5' are inaccessible.
    1.45 +
    1.46 +        P1 foo = null;
    1.47 +        P1.P3 bar = null;                       // ERROR
    1.48 +        P1.P3.P4 baz = null;                    // ERROR
    1.49 +        P1.P3.P4.P5 quux = null;                // ERROR
    1.50 +    }
    1.51 +
    1.52 +    void test2() {
    1.53 +
    1.54 +        // Inaccessible types in casts.
    1.55 +        // These exercise 'FieldExpression.checkCommon'.
    1.56 +        //
    1.57 +        // Fields 'P3' and 'P5' are inaccessible.
    1.58 +
    1.59 +        Object foo = (P1)null;
    1.60 +        Object bar = (P1.P3)null;               // ERROR
    1.61 +        Object baz = (P1.P3.P4)null;            // ERROR
    1.62 +        Object quux = (P1.P3.P4.P5)null;        // ERROR
    1.63 +    }
    1.64 +
    1.65 +    void test3() {
    1.66 +
    1.67 +        // Inaccessible types in 'instanceof' expressions.
    1.68 +        // These exercise 'FieldExpression.checkCommon'.
    1.69 +        //
    1.70 +        // Fields 'P3' and 'P5' are inaccessible.
    1.71 +
    1.72 +        boolean foo = null instanceof P1;
    1.73 +        boolean bar = null instanceof P1.P3;            // ERROR
    1.74 +        boolean baz = null instanceof P1.P3.P4;         // ERROR
    1.75 +        boolean quux = null instanceof P1.P3.P4.P5;     // ERROR
    1.76 +    }
    1.77 +
    1.78 +}

mercurial