Groovy script cannot be executed due to "Method code too large" error

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform Notice: Data Center - This article applies to Atlassian products on the Data Center platform.

Note that this knowledge base article was created for the Data Center version of the product. Data Center knowledge base articles for non-Data Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

Groovy script cannot be triggered due to the following error:

For example, an error similar to this one appears in the browser (example exception thrown from Insight Script Console, but similar exceptions can be thrown when using other plugins that run Groovy scripts):

class com.riadalabs.jira.plugins.insight.common.exception.GroovyInsightException

GroovyInsightException: startup failed: General error during class generation: Method code too large! java.lang.RuntimeException: Method code too large! at
groovyjarjarasm.asm.MethodWriter.getSize(MethodWriter.java:2059) at groovyjarjarasm.asm.ClassWriter.toByteArray(ClassWriter.java:861) at
org.codehaus.groovy.control.CompilationUnit$17.call(CompilationUnit.java:850) at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1087) at
org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:624) at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:602) at
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:579) at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:323) at
groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:293) at groovy.lang.GroovyShell.parseClass(GroovyShell.java:677) at groovy.lang.GroovyShell.parse(GroovyShell.java:689) at
groovy.lang.GroovyShell.evaluate(GroovyShell.java:573) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:612) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:583) at
com.riadalabs.jira.plugins.insight.services.core.impl.GroovyServiceImpl.evaluateGroovy(GroovyServiceImpl.java:70) at
com.riadalabs.jira.plugins.insight.channel.web.api.rest.services.GroovyResource.controlGroovy(GroovyResource.java:42) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at
java.lang.reflect.Method.invoke(Method.java:498) at com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper$ResponseOutInvoker.lambda$_dispatch$0(DispatchProviderHelper.java:181) at
com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper.lambda$invokeMethodWithInterceptors$0(DispatchProviderHelper.java:81) at
com.atlassian.plugins.rest.common.interceptor.impl.DefaultMethodInvocation.invoke(DefaultMethodInvocation.java:53) at
com.atlassian.plugins.rest.common.expand.interceptor.ExpandInterceptor.intercept(ExpandInterceptor.java:42) at
com.atlassian.plugins.rest.common.interceptor.impl.DefaultMethodInvocation.invoke(DefaultMethodInvocation.java:53) at
com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper.invokeMethodWithInterceptors(DispatchProviderHelper.java:106) at
com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper$ResponseOutInvoker._dispatch(DispatchProviderHelper.java:180) at
com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) at 

Environment

Jira with a plugin that runs Groovy scripts (e.g. Scriptrunner, Insight).

Diagnosis

  • The error started to appear suddenly, whilst the script code getting extended.
  • Some methods in the code got to large in size.
  • The code has grown and number of lines got rapidly increased.

Cause

This error basically means there is / are large methods in Groovy code: JVM has a limitation where a method cannot be larger than 64 kB. This means the behaviour is not caused by the triggering plugin itself, but it rather exists due to this JVM limitation.

Solution

The way to resolve this would be to rewrite / reorganize the code:

  • Split large methods in a number of smaller ones.
  • Check if the main method contains code that repeat itself consecutively (e.g. debugging function that keeps logging through code execution, like on the example screenshot in the "Problem" section). In that case, putting the code chunk in a loop would help to circumvent the limitation.

Notes

Additional information / articles about "Method code too large":

Last modified on Oct 13, 2021

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.