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

30 lines
797 B
Java

/*
* @test /nodynamiccopyright/
* @bug 8206986 8226510
* @summary Verify than a switch that does not yield a value is rejected.
* @compile/fail/ref=EmptySwitch.out -XDrawDiagnostics -XDshould-stop.at=FLOW EmptySwitch.java
*/
public class EmptySwitch {
private void print(EmptySwitchEnum t) {
(switch (t) {
}).toString();
(switch (t) {
default -> throw new IllegalStateException();
}).toString();
(switch (t) {
default: throw new IllegalStateException();
}).toString();
(switch (0) {
case 0: yield "";
default:
}).toString();
(switch (0) {
case 0 -> { yield ""; }
default -> { }
}).toString();
}
enum EmptySwitchEnum {
}
}