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

お困りですか?

アトラシアン コミュニティをご利用ください。

コミュニティに質問

プラットフォームについて: Data Center のみ - この記事は、Data Center プラットフォームのアトラシアン製品にのみ適用されます。

この KB は Data Center バージョンの製品用に作成されています。Data Center 固有ではない機能の Data Center KB は、製品のサーバー バージョンでも動作する可能性はありますが、テストは行われていません。サーバー*製品のサポートは 2024 年 2 月 15 日に終了しました。サーバー製品を利用している場合は、アトラシアンのサーバー製品のサポート終了のお知らせページにて移行オプションをご確認ください。

*Fisheye および Crucible は除く

要約

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 

環境

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

診断

  • 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.

原因

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.

ソリューション

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.

注意

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

最終更新日: 2021 年 10 月 13 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する
Powered by Confluence and Scroll Viewport.