You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (JIRA)" <ji...@apache.org> on 2019/07/19 14:45:00 UTC

[jira] [Comment Edited] (GROOVY-9199) Code in finally block is ignored in IntelliJ IDEA debugger

    [ https://issues.apache.org/jira/browse/GROOVY-9199?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16888941#comment-16888941 ] 

Eric Milles edited comment on GROOVY-9199 at 7/19/19 2:44 PM:
--------------------------------------------------------------

For comparison, here are the bytecodes generated for Java and Groovy.

{code:java}
    public static void main(String[] args) { // line 2
        try {
            t(true);
        } finally {
            t(false);
        }
    }
{code}
{code}
  // Method descriptor #12 ([Ljava/lang/String;)V
  // Stack: 1, Locals: 2
  public static void main(java.lang.String[] arg0);
     0  iconst_1
     1  invokestatic Example.t(boolean) : void [2]
     4  iconst_0
     5  invokestatic Example.t(boolean) : void [2]
     8  goto 18
    11  astore_1
    12  iconst_0
    13  invokestatic Example.t(boolean) : void [2]
    16  aload_1
    17  athrow
    18  return
      Exception Table:
        [pc: 0, pc: 4] -> 11 when : any
      Line numbers:
        [pc: 0, line: 4]
        [pc: 4, line: 6]
        [pc: 8, line: 7]
        [pc: 11, line: 6]
        [pc: 16, line: 7]
        [pc: 18, line: 8]
      Stack map table: number of frames 2
        [pc: 11, same_locals_1_stack_item, stack: {java.lang.Throwable}]
        [pc: 18, same]
{code}

{code:groovy}
  static main(args) { // line 12
    try {
      t(true)
    } finally {
      t(false)
    }
  }
{code}
{code}
  // Method descriptor #28 ([Ljava/lang/String;)V
  // Stack: 1, Locals: 2
  public static void main(java.lang.String... args);
     0  iconst_1
     1  invokestatic Example.t(boolean) : void [33]
     4  aconst_null
     5  pop
     6  goto 9
     9  iconst_0
    10  invokestatic Example.t(boolean) : void [33]
    13  aconst_null
    14  pop
    15  goto 27
    18  astore_1
    19  iconst_0
    20  invokestatic Example.t(boolean) : void [33]
    23  aconst_null
    24  pop
    25  aload_1
    26  athrow
    27  return
      Exception Table:
        [pc: 0, pc: 9] -> 18 when : any
      Line numbers:
        [pc: 0, line: 13]
        [pc: 0, line: 14]
        [pc: 6, line: 15]
        [pc: 9, line: 16]
        [pc: 15, line: 17]
        [pc: 15, line: 17]
        [pc: 19, line: 16]
        [pc: 25, line: 17]
        [pc: 25, line: 17]
        [pc: 27, line: 18]
      Local variable table:
        [pc: 0, pc: 27] local: args index: 0 type: java.lang.String[]
      Stack map table: number of frames 3
        [pc: 9, same]
        [pc: 18, same_locals_1_stack_item, stack: {java.lang.Throwable}]
        [pc: 27, same]
      Method Parameters:
        args
{code}

Note: Groovy was with invoke dynamic and static compilation enabled


was (Author: emilles):
For comparison, here are the bytecodes generated for Java and Groovy.

{code:java}
    public static void main(String[] args) { // line 2
        try {
            t(true);
        } finally {
            t(false);
        }
    }
{code}
{code}
  // Method descriptor #12 ([Ljava/lang/String;)V
  // Stack: 1, Locals: 2
  public static void main(java.lang.String[] arg0);
     0  iconst_1
     1  invokestatic Example.t(boolean) : void [2]
     4  iconst_0
     5  invokestatic Example.t(boolean) : void [2]
     8  goto 18
    11  astore_1
    12  iconst_0
    13  invokestatic Example.t(boolean) : void [2]
    16  aload_1
    17  athrow
    18  return
      Exception Table:
        [pc: 0, pc: 4] -> 11 when : any
      Line numbers:
        [pc: 0, line: 4]
        [pc: 4, line: 6]
        [pc: 8, line: 7]
        [pc: 11, line: 6]
        [pc: 16, line: 7]
        [pc: 18, line: 8]
      Stack map table: number of frames 2
        [pc: 11, same_locals_1_stack_item, stack: {java.lang.Throwable}]
        [pc: 18, same]
{code}

{code:groovy}
  static main(args) { // line 12
    try {
      t(true)
    } finally {
      t(false)
    }
  }
{code}
{code}
  // Method descriptor #28 ([Ljava/lang/String;)V
  // Stack: 1, Locals: 2
  public static void main(java.lang.String... args);
     0  iconst_1
     1  invokestatic Transient.t(boolean) : void [33]
     4  aconst_null
     5  pop
     6  goto 9
     9  iconst_0
    10  invokestatic Transient.t(boolean) : void [33]
    13  aconst_null
    14  pop
    15  goto 27
    18  astore_1
    19  iconst_0
    20  invokestatic Transient.t(boolean) : void [33]
    23  aconst_null
    24  pop
    25  aload_1
    26  athrow
    27  return
      Exception Table:
        [pc: 0, pc: 9] -> 18 when : any
      Line numbers:
        [pc: 0, line: 13]
        [pc: 0, line: 14]
        [pc: 6, line: 15]
        [pc: 9, line: 16]
        [pc: 15, line: 17]
        [pc: 15, line: 17]
        [pc: 19, line: 16]
        [pc: 25, line: 17]
        [pc: 25, line: 17]
        [pc: 27, line: 18]
      Local variable table:
        [pc: 0, pc: 27] local: args index: 0 type: java.lang.String[]
      Stack map table: number of frames 3
        [pc: 9, same]
        [pc: 18, same_locals_1_stack_item, stack: {java.lang.Throwable}]
        [pc: 27, same]
      Method Parameters:
        args
{code}

Note: Groovy was with invoke dynamic and static compilation enabled

> Code in finally block is ignored in IntelliJ IDEA debugger
> ----------------------------------------------------------
>
>                 Key: GROOVY-9199
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9199
>             Project: Groovy
>          Issue Type: Improvement
>          Components: bytecode
>    Affects Versions: 2.5.7
>            Reporter: Andres Almiray
>            Priority: Major
>         Attachments: example_2_5_4.txt, example_2_5_7.txt
>
>
> A single line of code in a {{finally}} block is ignored. Given then following example code
> {code:java}
> class Example {
>     static void t(boolean t) {
>         if (t) {
>             throw new RuntimeException();
>         }
>     }
>     static void example() {
>         try {
>             t(true)   // <- break point here!
>         } finally {
>             t(false)
>         }
>     }
>     static void main(String[] args) {
>         example()
>     }
> }
> {code}
> When you run this code in the IntelliJ IDEA debugger makes the {{t(false)}} appears as it's not executed. The line numbers are misleading.
> Code works in 2.5.4 but it's broken since 2.5.5. Please see attached bytecode dumps.
>  
> Problem identified by [~godin] (JaCoCo). Observed and reported at JCrete 2019 hackfest.



--
This message was sent by Atlassian JIRA
(v7.6.14#76016)