-
Bug
-
Resolution: Fixed
-
P4
-
21, 22
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8334614 | 21.0.5-oracle | Ravi Reddy | P4 | Resolved | Fixed | b02 |
JDK-8336388 | 21.0.5 | Matthias Baesken | P4 | Resolved | Fixed | b01 |
ADDITIONAL SYSTEM INFORMATION :
Mac M1
openjdk version "21" 2023-09-19
OpenJDK Runtime Environment (build 21+35-2513)
OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
I see an infinite loop with with JDK 21 with this pattern match particularly with guarded match.
Able to replicate every single time.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this code.
----
import java.util.Objects;
public class Replicate {
record Point(Object a, Object b){}
public static void main(String[] args) {
find(new Point(5, null));
find(new Point(5, 4.5));
}
private static void find(Object point){
switch (point){
case Point(Integer a, Integer b) -> System.out.println("both ints");
case Point(Integer a, var b) when tester(b) -> System.out.println("not null");
case Point(Integer a, var b) -> System.out.println("null");
case null, default -> System.out.println("Unexpected value: " + point);
}
}
private static boolean tester(Object b){
System.out.println("received : " + b);
return Objects.nonNull(b);
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should print this and terminate.
---
received: null
null
received: 4.5
not null
ACTUAL -
Prints below infinitely
---
received: null
---------- BEGIN SOURCE ----------
import java.util.Objects;
public class Replicate {
record Point(Object a, Object b){}
public static void main(String[] args) {
find(new Point(5, null));
find(new Point(5, 4.5));
}
private static void find(Object point){
switch (point){
case Point(Integer a, Integer b) -> System.out.println("both ints");
case Point(Integer a, var b) when tester(b) -> System.out.println("not null");
case Point(Integer a, var b) -> System.out.println("null");
case null, default -> System.out.println("Unexpected value: " + point);
}
}
private static boolean tester(Object b){
System.out.println("received : " + b);
return Objects.nonNull(b);
}
}
---------- END SOURCE ----------
FREQUENCY : always
Mac M1
openjdk version "21" 2023-09-19
OpenJDK Runtime Environment (build 21+35-2513)
OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
I see an infinite loop with with JDK 21 with this pattern match particularly with guarded match.
Able to replicate every single time.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this code.
----
import java.util.Objects;
public class Replicate {
record Point(Object a, Object b){}
public static void main(String[] args) {
find(new Point(5, null));
find(new Point(5, 4.5));
}
private static void find(Object point){
switch (point){
case Point(Integer a, Integer b) -> System.out.println("both ints");
case Point(Integer a, var b) when tester(b) -> System.out.println("not null");
case Point(Integer a, var b) -> System.out.println("null");
case null, default -> System.out.println("Unexpected value: " + point);
}
}
private static boolean tester(Object b){
System.out.println("received : " + b);
return Objects.nonNull(b);
}
}
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The program should print this and terminate.
---
received: null
null
received: 4.5
not null
ACTUAL -
Prints below infinitely
---
received: null
---------- BEGIN SOURCE ----------
import java.util.Objects;
public class Replicate {
record Point(Object a, Object b){}
public static void main(String[] args) {
find(new Point(5, null));
find(new Point(5, 4.5));
}
private static void find(Object point){
switch (point){
case Point(Integer a, Integer b) -> System.out.println("both ints");
case Point(Integer a, var b) when tester(b) -> System.out.println("not null");
case Point(Integer a, var b) -> System.out.println("null");
case null, default -> System.out.println("Unexpected value: " + point);
}
}
private static boolean tester(Object b){
System.out.println("received : " + b);
return Objects.nonNull(b);
}
}
---------- END SOURCE ----------
FREQUENCY : always
- backported by
-
JDK-8334614 Java Record Pattern Match leads to infinite loop
- Resolved
-
JDK-8336388 Java Record Pattern Match leads to infinite loop
- Resolved
- duplicates
-
JDK-8326573 Switch expression causes infinite loop
- Closed
- links to
-
Commit openjdk/jdk/93a2e773
-
Commit(master) openjdk/jdk21u-dev/f704b622
-
Review openjdk/jdk/17951
-
Review(master) openjdk/jdk21u-dev/835
(2 links to)