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

Surprising behavior of step over in String switch

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 17
    • 17
    • tools
    • None
    • b12

      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.

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

              Created:
              Updated:
              Resolved: