langtools/test/tools/javac/InnerNamedConstant_2.java
author lana
Thu, 21 Jan 2016 09:46:01 -0800
changeset 35340 38f7386ed942
parent 6150 d055fa8ced62
permissions -rw-r--r--
Added tag jdk-9+102 for changeset 7e3feb2ba5b3
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
 *
6150
d055fa8ced62 6971882: Remove -XDstdout from javac test
jjg
parents: 863
diff changeset
     7
 * @compile/fail/ref=InnerNamedConstant_2.out -XDrawDiagnostics 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
}