-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P3
-
Affects Version/s: 21
-
Component/s: tools
-
b03
| Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
|---|---|---|---|---|---|---|
| JDK-8311327 | 21.0.1 | Jan Lahoda | P3 | Resolved | Fixed | b02 |
| JDK-8310503 | 21 | Jan Lahoda | P3 | Resolved | Fixed | b29 |
Consider this snippet of code:
---
public class Test {
public static void main(String[] args) {
Object o = null;
switch (o) {
case String s when s.isEmpty() -> {
s = null;
}
default -> {}
}
}
}
---
javac accepts this code, even though 's' is not effectively final and is used inside the guard. But, variables declared outside of the guard must be (effectively) final.
---
public class Test {
public static void main(String[] args) {
Object o = null;
switch (o) {
case String s when s.isEmpty() -> {
s = null;
}
default -> {}
}
}
}
---
javac accepts this code, even though 's' is not effectively final and is used inside the guard. But, variables declared outside of the guard must be (effectively) final.
- backported by
-
JDK-8310503 Effectivelly final condition not enforced in guards for binding variables from the same case
-
- Resolved
-
-
JDK-8311327 Effectivelly final condition not enforced in guards for binding variables from the same case
-
- Resolved
-
- links to
-
Commit
openjdk/jdk21/ceadaece
-
Commit
openjdk/jdk/01623f6a
-
Review
openjdk/jdk21/46
-
Review
openjdk/jdk/14498
(1 links to)