RFR: 8261606: Surprising behavior of step over in String switch

Jan Lahoda jlahoda at openjdk.java.net
Mon Feb 15 08:16:50 UTC 2021

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
                    System.out.println("default"); //the program counter will be shown here eventually
        } else {

Placing breakpoint at the marked line (with `System.out.println("a");`), running debugger and performing step-over, the execution eventually is shown to stop at the line with `System.out.println("default");`.

The reason for this is (roughly) because the switch-over-string is desugared into a block, but that block does not have an end position set. So the LineNumberTable point for the closing bracket of the block is not generated, and hence the last previous point is used, which is the last line of the last case (branch) of the switch.

The proposal is to set the end position for the synthetic block generated for the switch-over-string.


Commit messages:
 - 8261606: Surprising behavior of step over in String switch

Changes: https://git.openjdk.java.net/jdk/pull/2569/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=2569&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8261606
  Stats: 80 lines in 5 files changed: 79 ins; 0 del; 1 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2569.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2569/head:pull/2569

PR: https://git.openjdk.java.net/jdk/pull/2569

More information about the compiler-dev mailing list