Details
-
Bug
-
Resolution: Fixed
-
P3
-
17, 18, 19, 20, 21, 22
-
b10
Backports
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8325971 | 22.0.1 | Angelos Bimpoudis | P3 | Resolved | Fixed | b05 |
Description
Consider debugging the code with jdk 17:
public class DebuggingSwitch {
public static void main(String[] args) throws Exception {
String returnValue;
try {
System.out.println("Enter the try catch block");
throw new Exception("Error");
} catch(Exception e) {
returnValue = switch(e.getMessage()) { // breakpoint here and start stepping over
case "Error" -> {
System.out.println("Error exception"); // 1 stop - ok
yield "Error"; // 2 stop - ok
}
case "Warning" -> {
System.out.println("Warning exception");
yield "Warning";
}
default -> {
System.out.println("Default exception");
System.out.println("Another default exception");
throw e; // 2 stop - NOT OK
}
};
}
}
}
Set a breakpoint at the switch line inside the catch block, then step over several times. On the third stop it will stop at the line with "throw e;" inside the default block which is definitely not executed, which is really misleading.
Originally the problem was reported here: https://youtrack.jetbrains.com/issue/IDEA-316450
public class DebuggingSwitch {
public static void main(String[] args) throws Exception {
String returnValue;
try {
System.out.println("Enter the try catch block");
throw new Exception("Error");
} catch(Exception e) {
returnValue = switch(e.getMessage()) { // breakpoint here and start stepping over
case "Error" -> {
System.out.println("Error exception"); // 1 stop - ok
yield "Error"; // 2 stop - ok
}
case "Warning" -> {
System.out.println("Warning exception");
yield "Warning";
}
default -> {
System.out.println("Default exception");
System.out.println("Another default exception");
throw e; // 2 stop - NOT OK
}
};
}
}
}
Set a breakpoint at the switch line inside the catch block, then step over several times. On the third stop it will stop at the line with "throw e;" inside the default block which is definitely not executed, which is really misleading.
Originally the problem was reported here: https://youtrack.jetbrains.com/issue/IDEA-316450
Attachments
Issue Links
- backported by
-
JDK-8325971 Incorrect stepping in switch
- Resolved
- relates to
-
JDK-8261606 Surprising behavior of step over in String switch
- Resolved
- links to
-
Commit openjdk/jdk22u/457526d9
-
Commit openjdk/jdk/e3dc6a7a
-
Review openjdk/jdk17u/387
-
Review openjdk/jdk21u/437
-
Review openjdk/jdk22u/47
-
Review openjdk/jdk/17772
(3 links to)