Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy ConfigSlurper gives Class file too large RuntimeException

I am using the Groovy ConfigSlurper to load a large groovy file (741KB) from a Groovy script and consistently receive a RuntimeException when it tries to do the compilation.

Groovy 2.1.1, Java 1.6 (Apple/MacOSX)

I call it like so:

conf = new ConfigSlurper().parse(new File('conf.groovy').toURL())

And always get the exception below. Is there a known limitation to the size of a file ConfigSlurper can compile?

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
General error during class generation: Class file too large!

java.lang.RuntimeException: Class file too large!
  at org.objectweb.asm.ClassWriter.toByteArray(Unknown Source)
  at org.codehaus.groovy.control.CompilationUnit$15.call(CompilationUnit.java:797)
  at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1036)
  at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:573)
  at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:551)
  at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:528)
  at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
  at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
  at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
  at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:202)
  at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:212)
  at groovy.lang.GroovyClassLoader$parseClass.call(Unknown Source)
  at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
  at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
  at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
  at groovy.util.ConfigSlurper.parse(ConfigSlurper.groovy:146)
  at groovy.util.ConfigSlurper$parse.call(Unknown Source)
  at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
  at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
  at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
  at write_users.run(write_users.groovy:19)
  at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:257)
  at groovy.lang.GroovyShell.run(GroovyShell.java:220)
  at groovy.lang.GroovyShell.run(GroovyShell.java:150)
  at groovy.ui.GroovyMain.processOnce(GroovyMain.java:588)
  at groovy.ui.GroovyMain.run(GroovyMain.java:375)
  at groovy.ui.GroovyMain.process(GroovyMain.java:361)
  at groovy.ui.GroovyMain.processArgs(GroovyMain.java:120)
  at groovy.ui.GroovyMain.main(GroovyMain.java:100)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:106)
  at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:128)

1 error
like image 569
craig.schneider Avatar asked Jul 20 '13 04:07

craig.schneider


1 Answers

There is a known limitation but it is arguably not Groovy; it is the ASM library and ultimately Java.

As Stuart Halloway has mentioned in talks, it is often insightful to know what is happening one layer below your level of abstraction.

For example, this link shows that this code:

public byte[] toByteArray() {
        if (index > Short.MAX_VALUE) {
            throw new RuntimeException("Class file too large!");
        }

... is likely the exception shown here:

java.lang.RuntimeException: Class file too large!
  at org.objectweb.asm.ClassWriter.toByteArray(Unknown Source)

Why does the ASM method throw this exception? This post states:

It turns out that the magic number for the "code too large" error is 65535 bytes (compiled byte code, not source code).

It is probable that the file is too large for Groovy's internal implementation, which would result in a synthetic method that is too large for the JVM.

like image 152
Michael Easter Avatar answered Oct 11 '22 08:10

Michael Easter