aspose file tools
The moose likes Groovy and the fly likes Invalid method Code length Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Other Languages » Groovy
Reply Bookmark "Invalid method Code length" Watch "Invalid method Code length" New topic
Author

Invalid method Code length

Nishnt Rayn
Greenhorn

Joined: Oct 23, 2008
Posts: 14
I get the following error when i try to compile a generated groovy code. After pounding for several hours still unable to find solution !! Will anyone help me out

Caused by: java.lang.ClassFormatError: Invalid method Code length 67932 in class file MyGroovyClass$_execute_closure17
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at groovy.lang.GroovyClassLoader.access$300(GroovyClassLoader.java:57)
at groovy.lang.GroovyClassLoader$ClassCollector.createClass(GroovyClassLoader.java:445)
at groovy.lang.GroovyClassLoader$ClassCollector.onClassNode(GroovyClassLoader.java:463)
at groovy.lang.GroovyClassLoader$ClassCollector.call(GroovyClassLoader.java:467)
at org.codehaus.groovy.control.CompilationUnit$10.call(CompilationUnit.java:701)
at org.codehaus.groovy.control.CompilationUnit$10.call(CompilationUnit.java:709)
at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:885)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:436)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:277)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:248)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:243)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:205)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:215)
at com.loandukaan.creditpolicy.creditrules.groovy.GroovyCreditPolicy.<init>(GroovyCreditPolicy.java:43)
at com.loandukaan.creditpolicy.creditrules.BankCreditPolicies.<init>(BankCreditPolicies.java:36)
at com.loandukaan.creditpolicy.creditrules.CreditPolicyManager.init(CreditPolicyManager.java:62)
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.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1325)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1294)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1257)

the code which does the groovy class loading is,



I use groovy version 1.5.6. JDK 1.6.10



thanks,
nishant
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 32767
The bytecode for Java methods has a maximum of 64KB. It sounds as if the Groovy code -which is compiled into Java bytecode- exceeds that. Consider refactoring your code into smaller chunks.


Android appsImageJ pluginsJava web charts
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4695

Is there any particular reason you are using ClassLoaders?


A good workman is known by his tools.
Nishnt Rayn
Greenhorn

Joined: Oct 23, 2008
Posts: 14
@Marc
Is there any particular reason you are using ClassLoaders?


The groovy class is generated from a template and hence class loader is used.

@Ulf Dittmer
The bytecode for Java methods has a maximum of 64KB. It sounds as if the Groovy code -which is compiled into Java bytecode- exceeds that. Consider refactoring your code into smaller chunks.


Yes i came across this Wiki post which seems to have the answer however i am figuring out how to do it my case [ where groovy code is generated from template] . Is there an easier way to do it?


Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4695

Groovy is so dynamic a language that I can't imagine a valid reason for generating Groovy code from a template. I would love to read any online tutorials for such a topic if you know of any.
Nishnt Rayn
Greenhorn

Joined: Oct 23, 2008
Posts: 14
Marc Peabody wrote:Groovy is so dynamic a language that I can't imagine a valid reason for generating Groovy code from a template. I would love to read any online tutorials for such a topic if you know of any.

I have DSL code in a totally different format [legacy code] which gets converted to groovy code and executed. I use velocity to generate groovy class. After a bit of trying outs. i realized that its a particular "generated" closure thats causing this error.
Probably i should rethink my translation logic to break down bigger closures
My question is : is it anyway connected to the fact that i am using class loaders or its just a general limitation of 64K
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4695

The problem is definitely because of file size, not because of the classloaders.

There are so many Groovy syntax shortcuts available that I'm quite sure that the generated code could be brought down in size significantly. The easiest way to shorten Groovy code is to use the most appropriate iteration method. It's quite often that those with a Java background will always use each when something like collect could save multiple lines of code.
 
IntelliJ Java IDE
 
subject: Invalid method Code length
 
Threads others viewed
GroovyClassLoader - parse folder
Problem with the Sample Spring AOP application
How do I read the compile time error messages?
Spring Error Log
Groovy embedded in Java and maintenance
IntelliJ Java IDE