-
Bug
-
Resolution: Fixed
-
P4
-
21, 22, 23
-
b06
-
generic
-
generic
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8337357 | 23.0.2 | Jan Lahoda | P4 | Resolved | Fixed | b01 |
JDK-8337903 | 23.0.1 | Jan Lahoda | P4 | Resolved | Fixed | b06 |
JDK-8336250 | 23 | Jan Lahoda | P4 | Resolved | Fixed | b32 |
ADDITIONAL SYSTEM INFORMATION :
OS: Windows 11 Pro
java 22.0.1 2024-04-16
A DESCRIPTION OF THE PROBLEM :
When using a switch statement with pattern matching and a guard clause, one specific case label fails to compile, whereas an almost similar case compiles successfully. Both case labels should compile without errors. The only difference between the two labels is a mathematical operator in the guard clause. ( >= instead of > )
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile successfully
ACTUAL -
The code didn't compile and showed errors on a specific line that is almost identical to the previous line that has no errors.
---------- BEGIN SOURCE ----------
public class Test {
void t1(Object o) {
switch (o) {
case Point(int x, int y) when ((x >= 0) && (y != 0)) -> {} // this compiles by javac
case Point(int x, int y) when ((x > 0) && (y != 0)) -> {} // this doesn't compile by javac, only difference is > instead of >=
default -> {}
}
}
record Point(int x, int y) { }
}
---------- END SOURCE ----------
OS: Windows 11 Pro
java 22.0.1 2024-04-16
A DESCRIPTION OF THE PROBLEM :
When using a switch statement with pattern matching and a guard clause, one specific case label fails to compile, whereas an almost similar case compiles successfully. Both case labels should compile without errors. The only difference between the two labels is a mathematical operator in the guard clause. ( >= instead of > )
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The code should compile successfully
ACTUAL -
The code didn't compile and showed errors on a specific line that is almost identical to the previous line that has no errors.
---------- BEGIN SOURCE ----------
public class Test {
void t1(Object o) {
switch (o) {
case Point(int x, int y) when ((x >= 0) && (y != 0)) -> {} // this compiles by javac
case Point(int x, int y) when ((x > 0) && (y != 0)) -> {} // this doesn't compile by javac, only difference is > instead of >=
default -> {}
}
}
record Point(int x, int y) { }
}
---------- END SOURCE ----------
- backported by
-
JDK-8336250 Switch case with pattern matching and guard clause compiles inconsistently
- Resolved
-
JDK-8337357 Switch case with pattern matching and guard clause compiles inconsistently
- Resolved
-
JDK-8337903 Switch case with pattern matching and guard clause compiles inconsistently
- Resolved
- links to
-
Commit(jdk23) openjdk/jdk/e991c0f9
-
Commit(master) openjdk/jdk/537d20af
-
Review(jdk23) openjdk/jdk/20111
-
Review(master) openjdk/jdk/20093
(2 links to)