Mon, 03 Oct 2016 11:21:14 -0700
Added tag jdk8u122-b02 for changeset 2baeb96fa198
duke@1 | 1 | /* |
duke@1 | 2 | * @test /nodynamiccopyright/ |
duke@1 | 3 | * @bug 4095568 4277286 4785453 |
duke@1 | 4 | * @summary Verify rejection of illegal static variables in inner classes. |
duke@1 | 5 | * @author William Maddox (maddox) |
duke@1 | 6 | * |
jjg@611 | 7 | * @compile/fail/ref=InnerNamedConstant_2.out -XDrawDiagnostics InnerNamedConstant_2.java |
duke@1 | 8 | */ |
duke@1 | 9 | |
duke@1 | 10 | public class InnerNamedConstant_2 { |
duke@1 | 11 | |
duke@1 | 12 | static class Inner1 { |
duke@1 | 13 | static int x = 1; // OK - class is top-level |
duke@1 | 14 | static final int y = x * 5; // OK - class is top-level |
duke@1 | 15 | static final String z; // OK - class is top-level |
duke@1 | 16 | static { |
duke@1 | 17 | z = "foobar"; |
duke@1 | 18 | } |
duke@1 | 19 | } |
duke@1 | 20 | |
duke@1 | 21 | class Inner2 { |
duke@1 | 22 | static int x = 1; // ERROR - static not final |
duke@1 | 23 | static final String z; // ERROR - static blank final |
duke@1 | 24 | { |
duke@1 | 25 | z = "foobar"; // Error may be reported here. See 4278961. |
duke@1 | 26 | } |
duke@1 | 27 | } |
duke@1 | 28 | |
duke@1 | 29 | // This case must go in a separate class, as otherwise the detection |
duke@1 | 30 | // of the error is suppressed as a result of recovery from the other |
duke@1 | 31 | // errors. |
duke@1 | 32 | |
duke@1 | 33 | class Inner3 { |
duke@1 | 34 | static final int y = Inner1.x * 5; // ERROR - initializer not constant |
duke@1 | 35 | } |
duke@1 | 36 | |
duke@1 | 37 | } |