Hi guys,

we use a rather large enum to collect, categorize & edit employee types:

enum Type2 {
  PROGRAMMER('DV_PR', Type1.M2, Type1.DEVELOPER, "Progr", "Programmer", [cat.WHITE_COLLAR, cat.PROPELLERHEAD])
  // ... many more entries like this
}

Until recently it had about 700 entries and everything worked fine, but when we tried to add the final required entries, getting to slightly below 1200 entries in all, the enum class started throwing:

groovyjarjarasm.asm.MethodTooLargeException: Method too large: Type2.<clinit>

during the build. Evidently Groovy runs into a JVM restriction that limits the maxium space a method can have in the generated bytecode.

Oddly enough, a Groovy class we implemented as a workaround that (alas akwardly) simulates the enum behavior as much as possible through static properties can initialize all its "enum" members inside a single static initEntries() method, called from the class' static ctor, without any problems, even though we would expect that to be about the same code the Type2 enum's static ctor should be required to execute to initialize its enum entries.

On the other hand even reducing the Type2 ctor to taking a single int argument (e.g. PROGRAMMER(123) ) still leads to the MethodTooLargeException...

Any ideas how we could get back to using the enum instead of our inferior workaround class ?

(The by-design tightly sealead nature of enum classes at least seems to prevent any conventional workaround. We als decided against trying to use reflection magic to go around these restrictions since it rules out Intellisense support, for fear of this approach breaking in the future, etc.)

Cheers,
mg

PS: Evidently Kotlin has introduced a compiler flag to be able to change the way enums are initialized to circumvent this problem, but from what I could gather the solution only works with parameterless enum ctors...



Reply via email to