java-topology/test/langtools/tools/javac/flow/T8030218/CompileTimeErrorForNonAssignedStaticFieldTest.java
russell@unturf.com 0a580b313d undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com

Patches, unit tests, benchmarks, whitepaper, and outreach briefs.
Public domain — no copyright claimed. Use freely.
2026-03-26 17:11:57 -04:00

29 lines
901 B
Java

/*
* @test /nodynamiccopyright/
* @bug 8030218
* @summary javac, compile time error isn't shown when final static field is not assigned, follow-up
* @compile/fail/ref=CompileTimeErrorForNonAssignedStaticFieldTest.out -XDrawDiagnostics CompileTimeErrorForNonAssignedStaticFieldTest.java
*/
public class CompileTimeErrorForNonAssignedStaticFieldTest {
private final static int i;
public CompileTimeErrorForNonAssignedStaticFieldTest()
throws InstantiationException {
throw new InstantiationException("Can't instantiate");
}
static class Inner {
private final int j;
public Inner(int x)
throws InstantiationException {
if (x == 0) {
throw new InstantiationException("Can't instantiate");
} else {
j = 1;
}
System.out.println(j);
}
}
}