langtools/test/tools/javac/InnerNamedConstant_2.java
author jjg
Thu, 10 Jul 2008 11:25:23 -0700
changeset 863 3113c955a388
parent 10 06bc494ca11e
child 6150 d055fa8ced62
permissions -rw-r--r--
6724327: eliminate use of shell tests for simple golden file tests Reviewed-by: darcy
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 4095568 4277286 4785453
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 * @summary Verify rejection of illegal static variables in inner classes.
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * @author William Maddox (maddox)
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 *
863
3113c955a388 6724327: eliminate use of shell tests for simple golden file tests
jjg
parents: 10
diff changeset
     7
 * @compile/fail/ref=InnerNamedConstant_2.out -XDrawDiagnostics -XDstdout InnerNamedConstant_2.java
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
public class InnerNamedConstant_2 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
    static class Inner1 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
        static int x = 1;                  // OK - class is top-level
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
        static final int y = x * 5;        // OK - class is top-level
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
        static final String z;             // OK - class is top-level
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
        static {
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
            z = "foobar";
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 Inner2 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
        static int x = 1;                  // ERROR - static not final
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
        static final String z;             // ERROR - static blank final
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
        {
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
            z = "foobar";                  // Error may be reported here. See 4278961.
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
    // This case must go in a separate class, as otherwise the detection
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
    // of the error is suppressed as a result of recovery from the other
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
    // errors.
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
    class Inner3 {
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
        static final int y = Inner1.x * 5; // ERROR - initializer not constant
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
}