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

Jan Lahoda jlahoda at
Tue Mar 2 12:05:49 UTC 2021

On Mon, 15 Feb 2021 08:12:10 GMT, Jan Lahoda <jlahoda at> 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.

This pull request has now been integrated.

Changeset: 85a5ae8c
Author:    Jan Lahoda <jlahoda at>
Stats:     80 lines in 5 files changed: 79 ins; 0 del; 1 mod

8261606: Surprising behavior of step over in String switch

Reviewed-by: vromero



More information about the compiler-dev mailing list