2

I'm new to Groovy and Java. I'm trying to compile an enum so I can use it in multiple other Groovy scripts.

Here's the enum:

package branchformatter

enum ColorSequence
{
    COLUMNS,
    WHEEL
}

When I try to compile it with groovyc it seems to compile without error but when I import it into another script and try to run the second script I get the following error:

the number of constructors during runtime and compile time for branchformatter.ColorSequence do not match. Expected -1 but got 2

I tried compiling the enum using Groovy Console and got the following exception:

java.lang.InstantiationException: branchformatter.ColorSequence

The weird thing is that if I copy and paste the enum definition into the second script directly, instead of trying to import it, the second script works fine. So there doesn't seem to be anything fundamentally wrong with the enum.

I'm running Groovy 2.2.1 and Java 1.7.0_51. I'm trying to execute the second script from within Freeplane 1.2.23 (mind mapping application).

EDIT: This is how I'm using it in the second script:

import branchformatter.ColorSequence

def colorSequence = ColorSequence.WHEEL

if (colorSequence == ColorSequence.COLUMNS)
{
    ...
}

EDIT 2, in response to chrylis asking to see what the decompiled enum looks like: Haven't got the JDK installed, only the JRE, and it looks like the JDK is a huge install so may take a while. Instead, I downloaded the JD-GUI, as described in this answer: https://stackoverflow.com/a/272595/216440 . Here's the output after it decompiled the enum class file:

package branchformatter;

import groovy.lang.GroovyObject;
import groovy.lang.MetaClass;
import java.util.LinkedHashMap;
import org.codehaus.groovy.runtime.BytecodeInterface8;
import org.codehaus.groovy.runtime.ScriptBytecodeAdapter;
import org.codehaus.groovy.runtime.callsite.CallSite;
import org.codehaus.groovy.transform.ImmutableASTTransformation;

public enum ColorSequence
  implements GroovyObject
{
  public static final ColorSequence MIN_VALUE;
  public static final ColorSequence MAX_VALUE;

  public ColorSequence(LinkedHashMap __namedArgs)
  {
    MetaClass localMetaClass = $getStaticMetaClass();
    this.metaClass = localMetaClass;
    if ((!BytecodeInterface8.isOrigZ()) || (BytecodeInterface8.disabledStandardMetaClass()))
    {
      if (ScriptBytecodeAdapter.compareEqual(__namedArgs, null)) {
        throw ((Throwable)arrayOfCallSite[0].callConstructor(IllegalArgumentException.class, "One of the enum constants for enum branchformatter.ColorSequence was initialized with null. Please use a non-null value or define your own constructor."));
      } else {
        arrayOfCallSite[1].callStatic(ImmutableASTTransformation.class, this, __namedArgs);
      }
    }
    else if (ScriptBytecodeAdapter.compareEqual(__namedArgs, null)) {
      throw ((Throwable)arrayOfCallSite[2].callConstructor(IllegalArgumentException.class, "One of the enum constants for enum branchformatter.ColorSequence was initialized with null. Please use a non-null value or define your own constructor."));
    } else {
      arrayOfCallSite[3].callStatic(ImmutableASTTransformation.class, this, __namedArgs);
    }
  }

  public ColorSequence()
  {
    this((LinkedHashMap)ScriptBytecodeAdapter.castToType(arrayOfCallSite[4].callConstructor(LinkedHashMap.class), LinkedHashMap.class));
  }

  static
  {
    __$swapInit();
    long l1 = 0L;
    __timeStamp__239_neverHappen1390713687979 = l1;
    long l2 = 1390713687979L;
    __timeStamp = l2;
    Object localObject1 = $getCallSiteArray()[18].callStatic(ColorSequence.class, "COLUMNS", Integer.valueOf(0));
    COLUMNS = (ColorSequence)ScriptBytecodeAdapter.castToType(localObject1, ColorSequence.class);
    Object localObject2 = $getCallSiteArray()[19].callStatic(ColorSequence.class, "WHEEL", Integer.valueOf(1));
    WHEEL = (ColorSequence)ScriptBytecodeAdapter.castToType(localObject2, ColorSequence.class);
    ColorSequence localColorSequence1 = COLUMNS;
    MIN_VALUE = localColorSequence1;
    ColorSequence localColorSequence2 = WHEEL;
    MAX_VALUE = localColorSequence2;
    ColorSequence[] arrayOfColorSequence = { COLUMNS, WHEEL };
    $VALUES = arrayOfColorSequence;
  }
}

EDIT 3: Output of javap -c -p ColorSequence. Note that the output has been truncated as it exceeded the maximum length for a post:

Warning: Binary file ColorSequence contains branchformatter.ColorSequence
Compiled from "BranchFormatter.ColorSequence.groovy"
public final class branchformatter.ColorSequence extends java.lang.Enum<branchformatter.ColorSequence> implements groovy.lang.GroovyObject {
  public static final branchformatter.ColorSequence COLUMNS;

  public static final branchformatter.ColorSequence WHEEL;

  public static final branchformatter.ColorSequence MIN_VALUE;

  public static final branchformatter.ColorSequence MAX_VALUE;

  private static final branchformatter.ColorSequence[] $VALUES;

  private static org.codehaus.groovy.reflection.ClassInfo $staticClassInfo;

  public static transient boolean __$stMC;

  private transient groovy.lang.MetaClass metaClass;

  public static long __timeStamp;

  public static long __timeStamp__239_neverHappen1390713687979;

  private static java.lang.ref.SoftReference $callSiteArray;

  public branchformatter.ColorSequence(java.lang.String, int, java.util.LinkedHashMap);
    Code:
       0: invokestatic  #30                 // Method $getCallSiteArray:()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
       3: astore        4
       5: aload_0
       6: aload_1
       7: iload_2
       8: invokespecial #33                 // Method java/lang/Enum."<init>":(Ljava/lang/String;I)V
      11: aload_0
      12: invokevirtual #37                 // Method $getStaticMetaClass:()Lgroovy/lang/MetaClass;
      15: astore        5
      17: aload         5
      19: aload_0
      20: swap
      21: putfield      #39                 // Field metaClass:Lgroovy/lang/MetaClass;
      24: aload         5
      26: pop
      27: invokestatic  #45                 // Method org/codehaus/groovy/runtime/BytecodeInterface8.isOrigZ:()Z
      30: ifeq          42
      33: invokestatic  #48                 // Method org/codehaus/groovy/runtime/BytecodeInterface8.disabledStandardMetaClass:()Z
      36: ifne          42
      39: goto          89
      42: aload_3
      43: aconst_null
      44: invokestatic  #54                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.compareEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      47: ifeq          71
      50: aload         4
      52: ldc           #55                 // int 0
      54: aaload
      55: ldc           #57                 // class java/lang/IllegalArgumentException
      57: ldc           #59                 // String One of the enum constants for enum branchformatter.ColorSequence was initialized with null. Please use a non-null value or define your own constructor.
      59: invokeinterface #65,  3           // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.callConstructor:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      64: checkcast     #67                 // class java/lang/Throwable
      67: athrow
      68: goto          86
      71: aload         4
      73: ldc           #68                 // int 1
      75: aaload
      76: ldc           #70                 // class org/codehaus/groovy/transform/ImmutableASTTransformation
      78: aload_0
      79: aload_3
      80: invokeinterface #74,  4           // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.callStatic:(Ljava/lang/Class;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      85: pop
      86: goto          133
      89: aload_3
      90: aconst_null
      91: invokestatic  #54                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.compareEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      94: ifeq          118
      97: aload         4
      99: ldc           #75                 // int 2
     101: aaload
     102: ldc           #57                 // class java/lang/IllegalArgumentException
     104: ldc           #59                 // String One of the enum constants for enum branchformatter.ColorSequence was initialized with null. Please use a non-null value or define your own constructor.
     106: invokeinterface #65,  3           // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.callConstructor:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     111: checkcast     #67                 // class java/lang/Throwable
     114: athrow
     115: goto          133
     118: aload         4
     120: ldc           #76                 // int 3
     122: aaload
     123: ldc           #70                 // class org/codehaus/groovy/transform/ImmutableASTTransformation
     125: aload_0
     126: aload_3
     127: invokeinterface #74,  4           // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.callStatic:(Ljava/lang/Class;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     132: pop
     133: return

  public branchformatter.ColorSequence(java.lang.String, int);
    Code:
       0: invokestatic  #30                 // Method $getCallSiteArray:()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
       3: astore_3
       4: aload_0
       5: aload_1
       6: iload_2
       7: aload_3
       8: ldc           #84                 // int 4
      10: aaload
      11: ldc           #86                 // class java/util/LinkedHashMap
      13: invokeinterface #89,  2           // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.callConstructor:(Ljava/lang/Object;)Ljava/lang/Object;
      18: ldc           #86                 // class java/util/LinkedHashMap
      20: invokestatic  #93                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
      23: checkcast     #86                 // class java/util/LinkedHashMap
      26: invokespecial #95                 // Method "<init>":(Ljava/lang/String;ILjava/util/LinkedHashMap;)V
      29: return

  public static final branchformatter.ColorSequence[] values();
    Code:
       0: invokestatic  #30                 // Method $getCallSiteArray:()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
       3: astore_0
       4: getstatic     #99                 // Field $VALUES:[Lbranchformatter/ColorSequence;
       7: invokevirtual #105                // Method java/lang/Object.clone:()Ljava/lang/Object;
      10: ldc           #106                // class "[Lbranchformatter/ColorSequence;"
      12: invokestatic  #93                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
      15: checkcast     #106                // class "[Lbranchformatter/ColorSequence;"
      18: areturn
      19: aconst_null
      20: areturn

  public branchformatter.ColorSequence next();
    Code:
       0: invokestatic  #30                 // Method $getCallSiteArray:()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
       3: astore_1
       4: aload_1
       5: ldc           #109                // int 5
       7: aaload
       8: aload_1
       9: ldc           #110                // int 6
      11: aaload
      12: aload_0
      13: invokeinterface #114,  2          // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.callCurrent:(Lgroovy/lang/GroovyObject;)Ljava/lang/Object;
      18: invokeinterface #117,  2          // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.call:(Ljava/lang/Object;)Ljava/lang/Object;
      23: astore_2
      24: aload_2
      25: pop
      26: invokestatic  #45                 // Method org/codehaus/groovy/runtime/BytecodeInterface8.isOrigZ:()Z
      29: ifeq          47
      32: getstatic     #119                // Field __$stMC:Z
      35: ifne          47
      38: invokestatic  #48                 // Method org/codehaus/groovy/runtime/BytecodeInterface8.disabledStandardMetaClass:()Z
      41: ifne          47
      44: goto          78
      47: aload_2
      48: aload_1
      49: ldc           #120                // int 7
      51: aaload
      52: getstatic     #99                 // Field $VALUES:[Lbranchformatter/ColorSequence;
      55: invokeinterface #117,  2          // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.call:(Ljava/lang/Object;)Ljava/lang/Object;
      60: invokestatic  #123                // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.compareGreaterThanEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      63: ifeq          75
      66: iconst_0
      67: istore_3
      68: iload_3
      69: invokestatic  #129                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      72: astore_2
      73: iload_3
      74: pop
      75: goto          109
      78: aload_2
      79: aload_1
      80: ldc           #130                // int 8
      82: aaload
      83: getstatic     #99                 // Field $VALUES:[Lbranchformatter/ColorSequence;
      86: invokeinterface #117,  2          // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.call:(Ljava/lang/Object;)Ljava/lang/Object;
      91: invokestatic  #123                // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.compareGreaterThanEqual:(Ljava/lang/Object;Ljava/lang/Object;)Z
      94: ifeq          109
      97: iconst_0
      98: istore        4
     100: iload         4
     102: invokestatic  #129                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     105: astore_2
     106: iload         4
     108: pop
     109: aload_1
     110: ldc           #131                // int 9
     112: aaload
     113: getstatic     #99                 // Field $VALUES:[Lbranchformatter/ColorSequence;
     116: aload_2
     117: invokeinterface #133,  3          // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.call:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     122: ldc           #2                  // class branchformatter/ColorSequence
     124: invokestatic  #93                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
     127: checkcast     #2                  // class branchformatter/ColorSequence
     130: areturn
     131: aconst_null
     132: areturn

  public branchformatter.ColorSequence previous();
    Code:
       0: invokestatic  #30                 // Method $getCallSiteArray:()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
       3: astore_1
       4: aload_1
       5: ldc           #137                // int 10
       7: aaload
       8: aload_1
       9: ldc           #138                // int 11
      11: aaload
      12: aload_0
      13: invokeinterface #114,  2          // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.callCurrent:(Lgroovy/lang/GroovyObject;)Ljava/lang/Object;
      18: invokeinterface #117,  2          // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.call:(Ljava/lang/Object;)Ljava/lang/Object;
      23: astore_2
      24: aload_2
      25: pop
      26: invokestatic  #45                 // Method org/codehaus/groovy/runtime/BytecodeInterface8.isOrigZ:()Z
      29: ifeq          47
      32: getstatic     #119                // Field __$stMC:Z
      35: ifne          47
      38: invokestatic  #48                 // Method org/codehaus/groovy/runtime/BytecodeInterface8.disabledStandardMetaClass:()Z
      41: ifne          47
      44: goto          91
      47: aload_2
      48: iconst_0
      49: invokestatic  #129                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      52: invokestatic  #141                // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.compareLessThan:(Ljava/lang/Object;Ljava/lang/Object;)Z
      55: ifeq          88
      58: aload_1
      59: ldc           #142                // int 12
      61: aaload
      62: aload_1
      63: ldc           #143                // int 13
      65: aaload
      66: getstatic     #99                 // Field $VALUES:[Lbranchformatter/ColorSequence;
      69: invokeinterface #117,  2          // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.call:(Ljava/lang/Object;)Ljava/lang/Object;
      74: iconst_1
      75: invokestatic  #129                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      78: invokeinterface #133,  3          // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.call:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      83: astore_3
      84: aload_3
      85: astore_2
      86: aload_3
      87: pop
      88: goto          135
      91: aload_2
      92: iconst_0
      93: invokestatic  #129                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      96: invokestatic  #141                // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.compareLessThan:(Ljava/lang/Object;Ljava/lang/Object;)Z
      99: ifeq          135
     102: aload_1
     103: ldc           #144                // int 14
     105: aaload
     106: aload_1
     107: ldc           #145                // int 15
     109: aaload
     110: getstatic     #99                 // Field $VALUES:[Lbranchformatter/ColorSequence;
     113: invokeinterface #117,  2          // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.call:(Ljava/lang/Object;)Ljava/lang/Object;
     118: iconst_1
     119: invokestatic  #129                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
     122: invokeinterface #133,  3          // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.call:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     127: astore        4
     129: aload         4
     131: astore_2
     132: aload         4
     134: pop
     135: aload_1
     136: ldc           #146                // int 16
     138: aaload
     139: getstatic     #99                 // Field $VALUES:[Lbranchformatter/ColorSequence;
     142: aload_2
     143: invokeinterface #133,  3          // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.call:(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
     148: ldc           #2                  // class branchformatter/ColorSequence
     150: invokestatic  #93                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
     153: checkcast     #2                  // class branchformatter/ColorSequence
     156: areturn
     157: aconst_null
     158: areturn

  public static branchformatter.ColorSequence valueOf(java.lang.String);
    Code:
       0: invokestatic  #30                 // Method $getCallSiteArray:()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
       3: astore_1
       4: aload_1
       5: ldc           #148                // int 17
       7: aaload
       8: ldc           #2                  // class branchformatter/ColorSequence
      10: ldc           #2                  // class branchformatter/ColorSequence
      12: aload_0
      13: invokeinterface #74,  4           // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.callStatic:(Ljava/lang/Class;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      18: ldc           #2                  // class branchformatter/ColorSequence
      20: invokestatic  #93                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
      23: checkcast     #2                  // class branchformatter/ColorSequence
      26: areturn
      27: aconst_null
      28: areturn

  public static final branchformatter.ColorSequence $INIT(java.lang.Object...);
    Code:
       0: invokestatic  #30                 // Method $getCallSiteArray:()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
       3: astore_1
       4: iconst_0
       5: anewarray     #101                // class java/lang/Object
       8: iconst_1
       9: anewarray     #101                // class java/lang/Object
      12: dup
      13: iconst_0
      14: aload_0
      15: aastore
      16: iconst_1
      17: newarray       int
      19: dup
      20: iconst_0
      21: iconst_0
      22: iastore
      23: invokestatic  #155                // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.despreadList:([Ljava/lang/Object;[Ljava/lang/Object;[I)[Ljava/lang/Object;
      26: dup
      27: bipush        -1
      29: ldc           #2                  // class branchformatter/ColorSequence
      31: invokestatic  #159                // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.selectConstructorAndTransformArguments:([Ljava/lang/Object;ILjava/lang/Class;)I
      34: new           #2                  // class branchformatter/ColorSequence
      37: swap
      38: lookupswitch  { // 2
           -1348271900: 64
            -242181752: 93
               default: 134
          }
      64: dup_x1
      65: dup2_x1
      66: pop
      67: dup
      68: iconst_0
      69: aaload
      70: ldc           #161                // class java/lang/String
      72: invokestatic  #93                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
      75: checkcast     #161                // class java/lang/String
      78: swap
      79: dup
      80: iconst_1
      81: aaload
      82: invokestatic  #167                // Method org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.intUnbox:(Ljava/lang/Object;)I
      85: swap
      86: pop
      87: invokespecial #168                // Method "<init>":(Ljava/lang/String;I)V
      90: goto          144
      93: dup_x1
      94: dup2_x1
      95: pop
      96: dup
      97: iconst_0
      98: aaload
      99: ldc           #161                // class java/lang/String
     101: invokestatic  #93                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
     104: checkcast     #161                // class java/lang/String
     107: swap
     108: dup
     109: iconst_1
     110: aaload
     111: invokestatic  #167                // Method org/codehaus/groovy/runtime/typehandling/DefaultTypeTransformation.intUnbox:(Ljava/lang/Object;)I
     114: swap
     115: dup
     116: iconst_2
     117: aaload
     118: ldc           #86                 // class java/util/LinkedHashMap
     120: invokestatic  #93                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
     123: checkcast     #86                 // class java/util/LinkedHashMap
     126: swap
     127: pop
     128: invokespecial #95                 // Method "<init>":(Ljava/lang/String;ILjava/util/LinkedHashMap;)V
     131: goto          144
     134: new           #57                 // class java/lang/IllegalArgumentException
     137: dup
     138: ldc           #170                // String This class has been compiled with a super class which is binary incompatible with the current super class found on classpath. You should recompile this class with the new version.
     140: invokespecial #173                // Method java/lang/IllegalArgumentException."<init>":(Ljava/lang/String;)V
     143: athrow
     144: swap
     145: pop
     146: areturn
     147: aconst_null
     148: areturn

  static {};
    Code:
       0: invokestatic  #180                // Method __$swapInit:()V
       3: lconst_0
       4: lstore_0
       5: lload_0
       6: putstatic     #182                // Field __timeStamp__239_neverHappen1390713687979:J
       9: lload_0
      10: pop2
      11: ldc2_w        #183                // long 1390713687979l
      14: lstore_2
      15: lload_2
      16: putstatic     #186                // Field __timeStamp:J
      19: lload_2
      20: pop2
      21: invokestatic  #30                 // Method $getCallSiteArray:()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
      24: ldc           #187                // int 18
      26: aaload
      27: ldc           #2                  // class branchformatter/ColorSequence
      29: ldc           #188                // String COLUMNS
      31: iconst_0
      32: invokestatic  #129                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      35: invokeinterface #74,  4           // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.callStatic:(Ljava/lang/Class;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      40: astore        4
      42: aload         4
      44: ldc           #2                  // class branchformatter/ColorSequence
      46: invokestatic  #93                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
      49: checkcast     #2                  // class branchformatter/ColorSequence
      52: putstatic     #190                // Field COLUMNS:Lbranchformatter/ColorSequence;
      55: aload         4
      57: pop
      58: invokestatic  #30                 // Method $getCallSiteArray:()[Lorg/codehaus/groovy/runtime/callsite/CallSite;
      61: ldc           #191                // int 19
      63: aaload
      64: ldc           #2                  // class branchformatter/ColorSequence
      66: ldc           #192                // String WHEEL
      68: iconst_1
      69: invokestatic  #129                // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
      72: invokeinterface #74,  4           // InterfaceMethod org/codehaus/groovy/runtime/callsite/CallSite.callStatic:(Ljava/lang/Class;Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
      77: astore        5
      79: aload         5
      81: ldc           #2                  // class branchformatter/ColorSequence
      83: invokestatic  #93                 // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
      86: checkcast     #2                  // class branchformatter/ColorSequence
      89: putstatic     #194                // Field WHEEL:Lbranchformatter/ColorSequence;
      92: aload         5
      94: pop
      95: getstatic     #190                // Field COLUMNS:Lbranchformatter/ColorSequence;
      98: astore        6
     100: aload         6
     102: putstatic     #196                // Field MIN_VALUE:Lbranchformatter/ColorSequence;
     105: aload         6
     107: pop
     108: getstatic     #194                // Field WHEEL:Lbranchformatter/ColorSequence;
     111: astore        7
     113: aload         7
     115: putstatic     #198                // Field MAX_VALUE:Lbranchformatter/ColorSequence;
     118: aload         7
     120: pop
     121: iconst_2
     122: anewarray     #2                  // class branchformatter/ColorSequence
     125: dup
     126: iconst_0
     127: getstatic     #190                // Field COLUMNS:Lbranchformatter/ColorSequence;
     130: aastore
     131: dup
     132: iconst_1
     133: getstatic     #194                // Field WHEEL:Lbranchformatter/ColorSequence;
     136: aastore
     137: astore        8
     139: aload         8
     141: putstatic     #99                 // Field $VALUES:[Lbranchformatter/ColorSequence;
     144: aload         8
     146: pop
     147: return

  protected groovy.lang.MetaClass $getStaticMetaClass();
    Code:
       0: aload_0
       1: invokevirtual #202                // Method java/lang/Object.getClass:()Ljava/lang/Class;
       4: ldc           #2                  // class branchformatter/ColorSequence
       6: if_acmpeq     14
       9: aload_0
      10: invokestatic  #206                // Method org/codehaus/groovy/runtime/ScriptBytecodeAdapter.initMetaClass:(Ljava/lang/Object;)Lgroovy/lang/MetaClass;
      13: areturn
      14: getstatic     #208                // Field $staticClassInfo:Lorg/codehaus/groovy/reflection/ClassInfo;
      17: astore_1
      18: aload_1
      19: ifnonnull     34
      22: aload_0
      23: invokevirtual #202                // Method java/lang/Object.getClass:()Ljava/lang/Class;
      26: invokestatic  #214                // Method org/codehaus/groovy/reflection/ClassInfo.getClassInfo:(Ljava/lang/Class;)Lorg/codehaus/groovy/reflection/ClassInfo;
      29: dup
      30: astore_1
      31: putstatic     #208                // Field $staticClassInfo:Lorg/codehaus/groovy/reflection/ClassInfo;
      34: aload_1
      35: invokevirtual #217                // Method org/codehaus/groovy/reflection/ClassInfo.getMetaClass:()Lgroovy/lang/MetaClass;
      38: areturn

  public groovy.lang.MetaClass getMetaClass();
    Code:
       0: aload_0
       1: getfield      #39                 // Field metaClass:Lgroovy/lang/MetaClass;
       4: dup
       5: ifnull        9
       8: areturn
       9: pop
      10: aload_0
      11: dup
      12: invokevirtual #37                 // Method $getStaticMetaClass:()Lgroovy/lang/MetaClass;
      15: putfield      #39                 // Field metaClass:Lgroovy/lang/MetaClass;
      18: aload_0
      19: getfield      #39                 // Field metaClass:Lgroovy/lang/MetaClass;
      22: areturn

  public void setMetaClass(groovy.lang.MetaClass);
    Code:
       0: aload_0
       1: aload_1
       2: putfield      #39                 // Field metaClass:Lgroovy/lang/MetaClass;
       5: return

[[REMAINDER TRUNCATED]]
Community
  • 1
  • 1
Simon Elms
  • 17,832
  • 21
  • 87
  • 103
  • 1
    Can you post the output of `javap -c -p ColorSequence`? – chrylis -cautiouslyoptimistic- Jan 26 '14 at 05:46
  • 1
    If this decompilation is accurate (and a disassembly would still be more helpful), it looks like a major bug in `groovyc`'s handling of enums. Java enums are specifically not supposed to have public constructors (there are a few specifically-defined instances). The next step I'd try is to compile your enum in Java (since you have no behavior involved) and use it in Groovy. – chrylis -cautiouslyoptimistic- Jan 26 '14 at 21:46
  • @chrylis: Thanks. Have downloaded the JDK and Eclipse and am attempting to get to grips with it. I'll try javap on the enum class file but your idea of compiling the Groovy enum as Java sounds like it may be the solution. Will have to try it out after work (once I've figured out how to use Eclipse). – Simon Elms Jan 26 '14 at 22:35
  • 1
    You should use an IDE anyway. Rather than bare Eclipse, I recommend [Groovy/Grails Tool Suite](http://spring.io/tools/ggts), which is an Eclipse distribution that comes prepackaged with all of the Groovy toolkit (as well as Grails/Spring support, which you can ignore if you're not using it). I use it even though I'm not a Groovy person just because some of the tools I use (Logback) use Groovy DSLs for configuration, and GGTS gives me nice syntax highlighting and such. – chrylis -cautiouslyoptimistic- Jan 26 '14 at 23:35
  • @chrylis: I've installed the Groovy/Grails Tool Suite, thanks. I'm totally new to the Java/Groovy/Eclipse world so it looks like I'll need a free evening to get to grips with it. Probably won't get the chance for a couple of days. Will update after I've had a decent play with it. – Simon Elms Jan 27 '14 at 20:39

1 Answers1

2

This looks to me like it is caused by a difference in versions of Groovy and/or Java. I think this problem is likely caused by the fact that you're compiling it manualy, using groovyc 2.2.1, and Freeplane is trying to run it with it's own internal groovy library which may be on a different version.

http://freeplane.sourceforge.net/wiki/index.php/Scripting:_Update_Freeplane%27s_Groovy_version

This says that Freeplane comes with groovy 1.8.0. I would try updating Freeplane to use groovy 2.2.1, or else fall back to 1.8.0 for yourself and see if that solves it.

Two things just as general notes: First: Any time you see the 'wrong number of constructors' or 'imcompatible class change' errors, that's usually in indication that there's a java and/or groovy version problem. 9 times out of 10, that'll be the issue, in my experience.

Second thing is pretty basic if you've had experience with java/groovy, but i'll mention it anyway since you said you're new to both. If you're running a Groovy script, you don't need to precompile it. The Groovy shell will do that for you when it evaluates the script. Then you'll always be sure that it's compiled with the same version of groovy that's running it.

allTwentyQuestions
  • 1,160
  • 7
  • 11
  • Worked perfectly, thanks. One question: When you say you don't need to precompile a script you want to run, does that include scripts that are imported into other scripts? I've been playing around and, if I replace the class file of the compiled enum with the original groovy script that defines the enum, the script that imports it runs ok. But if I rename the enum in both the script that defines it and the script that imports it, it fails with an error "unable to resolve class _new name_". So I'm not sure if I have to compile scripts that are imported into other scripts or not. – Simon Elms Feb 06 '14 at 23:01
  • 1
    If this is something you want to run as a one-time script, the best option is often to just include all the needed classes in one script as static inner classes. If you want the script to depend on precompiled code in, say, another library or something, you'll have to add those jar files to the classpath at runtime (since you can't easily add a normal dependency to a third-party program). You can do that by calling: `this.class.classLoader.addURL()` problem with that is then you'll have to load classes by calling Class.forName(String), which is a pain. Inner class is better. – allTwentyQuestions Feb 07 '14 at 17:51
  • Thanks for the explanation. I guess I'm just used to Python where it's trivial to split classes and functions into different files without needing to compile them or anything. I'm getting the impression Groovy is good for small projects but it seems like, in complexity, it's half way between a scripting language and Java for larger projects. – Simon Elms Feb 07 '14 at 23:40