Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8314275

Incorrect stepping in switch

    XMLWordPrintable

Details

    • b10

    Backports

      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

        Attachments

          Issue Links

            Activity

              People

                abimpoudis Angelos Bimpoudis
                eushakov Egor Ushakov
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: