Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7918

Line number debug annotation missing on final return

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 2.4.7
    • Fix Version/s: None
    • Component/s: bytecode
    • Labels:
      None

      Description

      When debugging code in Groovy, if a method ends with a branching statement, the debugger will appear to step into the method. In Groovy 2.4.7 and IntelliJ 2016.2.2, if you run the class below with no arguments and place a breakpoint on line a, then choose to step one line, the debugger will appear to stop on line b.

      class Debugging {
      	public static void main(String[] args) {
      		a: if (args.length > 0) {
      			b: println "args"
      		}
      	} //line 6
      }
      

      The reason for this is in the bytecode:

         L3
          LINENUMBER 4 L3
          ALOAD 1
          LDC 1
          AALOAD
          LDC LDebugging;.class
          LDC "args"
          INVOKEINTERFACE org/codehaus/groovy/runtime/callsite/CallSite.callStatic (Ljava/lang/Class;Ljava/lang/Object;)Ljava/lang/Object;
          POP
         L2
          RETURN
      

      There's no LINENUMBER annotation on the final return, so the LINENUMBER 4 from earlier is used, which is inside the if block, even though the if block does not run.

      In Java, the final return is annotated with the line number of the closing brace, which in the example above is line 6.

      A workaround is to add an explicit "return" statement at the end of the method, which generates the line number annotation without changing the semantics.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                gillius Jason Winnebeck
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: