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

26 lines
747 B
Java

/**
* @test /nodynamiccopyright/
* @bug 8222850
* @summary Check error recovery for switch over undefined variables.
* @compile/fail/ref=SwitchUndefinedSelector.out -XDrawDiagnostics --should-stop=at=FLOW SwitchUndefinedSelector.java
*/
public class SwitchUndefinedSelector {
private static final Object D = null;
public void switchTest() {
switch (undefined) {
case A -> {}
case B, C -> {}
case D -> {}
}
var v = switch (undefined) {
case A -> 0;
case B, C -> 0;
case D -> 0;
};
switch (undefined) {
case SwitchUndefinedSelector.D -> {}
case SwitchUndefinedSelector.UNDEF -> {}
}
}
}