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

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Jan Lahoda-3
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.

-------------

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
Reply | Threaded
Open this post in threaded view
|

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

Vicente Romero-3
On Mon, 15 Feb 2021 08:12:10 GMT, Jan Lahoda <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

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

Jan Lahoda-3
In reply to this post by Jan Lahoda-3
On Mon, 15 Feb 2021 08:12:10 GMT, Jan Lahoda <[hidden email]> 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 <[hidden email]>
URL:       https://git.openjdk.java.net/jdk/commit/85a5ae8c
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

-------------

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