Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Duplicate
-
2.4.7
-
None
-
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
- duplicates
-
GROOVY-7647 Incorrect line information for debug
- Closed