JDK-8261606 : Surprising behavior of step over in String switch
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 17
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-02-11
  • Updated: 2024-02-08
  • Resolved: 2021-03-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 17
17 b12Fixed
Related Reports
Relates :  
Relates :  
Relates :  
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.

Comments
Changeset: 85a5ae8c Author: Jan Lahoda <jlahoda@openjdk.org> Date: 2021-03-02 12:02:26 +0000 URL: https://git.openjdk.java.net/jdk/commit/85a5ae8c
02-03-2021