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

Surprising behavior of step over in String switch

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 17
    • Fix Version/s: 17
    • Component/s: tools
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b12

      Description

      Consider code like:
      ---
      public class Test {
          public static void main(String... args) {
              new Test().test("a");
          }
          private void test(String s) {
              if (s != null) {
                  switch (s) {
                      case "a":
                          System.out.println("a"); //breakpoint here, and continue with step-over
                          break;
                      default:
                          System.out.println("default"); //the program counter will be shown here eventually
                  }
              } else {
                  System.out.println("null");
              }
          }
      }
      ---

      Place a breakpoint at the marked line, and continue with step-over. After a few steps, the current program counter marker will be at the line:
      System.out.println("default");

      The line will not be executed, but it will appear as if it would in the debugger.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              jlahoda Jan Lahoda
              Reporter:
              jlahoda Jan Lahoda
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: