Consider the following class:

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

And let's say that I run the program with no arguments, and I put IntelliJ 
debugger to break on line a. Now when I "step next" I see it highlight line b, 
then step next and the program ends. The line b clearly did not run. Is this a 
problem with IntelliJ or the bytecode? Below is the bytecode for the method. 
I'm assuming the issue is that L2 is before the return, and at the return 
bytecode we see before it LINENUMBER 4. If the return was annotated with a 
linenumber 5 or 6, I assume the debugger would step to the closing brace of the 
if statement (or of the method itself, depending on what was preferred). Is 
this an issue with the IntelliJ debugger, or is it really a limitation of the 
Groovy bytecode generation? A workaround is if I put an empty return statement 
at the end of main, the debugger works, but strangely in bytecode I see two 
returns.

  public static transient varargs main([Ljava/lang/String;)V
   L0
    INVOKESTATIC Debugging.$getCallSiteArray 
()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
    ASTORE 1
   L1
    LINENUMBER 3 L1
    ALOAD 1
    LDC 0
    AALOAD
    ALOAD 0
    INVOKEINTERFACE 
org/codehaus/groovy/runtime/callsite/CallSite.callGetProperty 
(Ljava/lang/Object;)Ljava/lang/Object;
    ICONST_0
    INVOKESTATIC java/lang/Integer.valueOf (I)Ljava/lang/Integer;
    INVOKESTATIC 
org/codehaus/groovy/runtime/ScriptBytecodeAdapter.compareGreaterThan 
(Ljava/lang/Object;Ljava/lang/Object;)Z
    IFEQ L2
   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
    LOCALVARIABLE args [Ljava/lang/String; L0 L2 0
    MAXSTACK = 3
    MAXLOCALS = 2

Jason Winnebeck

This email message and any attachments are for the sole use of the intended 
recipient(s). Any unauthorized review, use, disclosure or distribution is 
prohibited. If you are not the intended recipient, please contact the sender by 
reply email and destroy all copies of the original message and any attachments.

Reply via email to