java-topology/test/langtools/tools/javac/switchextra/DefiniteAssignment2.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

80 lines
1.2 KiB
Java

/**
* @test /nodynamiccopyright/
* @summary Verify that definite assignment works (illegal code)
* @compile/fail/ref=DefiniteAssignment2.out -XDrawDiagnostics DefiniteAssignment2.java
*/
public class DefiniteAssignment2 {
public static void meth() {
int a = 0;
E e = E.A;
{
int x;
switch(a) {
case 0: break;
default: x = 1; break;
}
System.err.println(x);
}
{
int x;
switch(a) {
case 0 -> {}
default -> x = 1;
}
System.err.println(x);
}
{
int x;
switch(a) {
case 0: x = 0; break;
default:
}
System.err.println(x);
}
{
int x;
switch(e) {
case A, B, C -> x = 0;
}
System.err.println(x);
}
{
int x;
switch(e) {
case A, B, C -> { x = 0; }
}
System.err.println(x);
}
{
int x;
switch(e) {
case A, B -> { x = 0; }
case C -> throw new IllegalStateException();
}
System.err.println(x);
}
}
enum E {
A, B, C;
}
}