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

25 lines
621 B
Java

/*
* @test /nodynamiccopyright/
* @bug 4725650
* @summary Restrict scope of local classes in switch-block-group
* @author gafter
*
* @compile/fail/ref=SwitchScope.out -XDrawDiagnostics SwitchScope.java
*/
public class SwitchScope {
public static void meth(String[] args) {
switch (args.length) {
case 0:
final int k;
k = 12;
class Local {
int j = k;
}
case 1:
// the scope of a local class does not extend from one
// switch case to the next.
Object o = new Local();
}
}
}