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

Vicente Romero vromero at openjdk.java.net
Wed Feb 17 03:05:42 UTC 2021

On Mon, 15 Feb 2021 08:12:10 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> 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");
>         }
>     }
> } 
> 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.

looks sensible


Marked as reviewed by vromero (Reviewer).

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

More information about the compiler-dev mailing list