Home » Javascript » javax.servlet.ServletException: javax.script.ScriptException: java.lang.RuntimeException: Method code too large! in <eval>

javax.servlet.ServletException: javax.script.ScriptException: java.lang.RuntimeException: Method code too large! in <eval>

Posted by: admin October 29, 2018 Leave a comment

Questions:

I am trying to call java Script function from java class using ScriptEngineManage. The size of the “js” file is very large. It giving the following error

HTTP Status 500 – javax.servlet.ServletException: javax.script.ScriptException: java.lang.RuntimeException: Method code too large! in at line number 2 at column number 2321421

Portion of java code is given below

public int HashSignature(String query) throws ClassNotFoundException, IOException, ScriptException,  NoSuchMethodException{

    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByExtension("js");
    Invocable inv = (Invocable) engine;
    FileReader reader = new FileReader("C:/Users/RIT/Desktop/post/web/js/pg_query.js");
    engine.eval(reader);
    String scriptPath1 = "C:/Users/RIT/Desktop/post/web/js/signature.js";
    engine.eval("load('" + scriptPath1 + "')");
    Object hash=inv.invokeFunction("signature_hash", "query"); }

Here signature_hash is the java script function defined in signature.js .
The detailed description of error given below

exception
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.script.ScriptException: java.lang.RuntimeException: Method code too large! in <eval> at line number 2 at column number 2321421
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:555)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:461)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

root cause

javax.servlet.ServletException: javax.script.ScriptException: java.lang.RuntimeException: Method code too large! in <eval> at line number 2 at column number 2321421
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:909)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:838)
    org.apache.jsp.attacker_005flogin_005fsave_jsp._jspService(attacker_005flogin_005fsave_jsp.java:169)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

root cause

javax.script.ScriptException: java.lang.RuntimeException: Method code too large! in <eval> at line number 2 at column number 2321421
jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:467)
jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:389)
jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:190)
com.DetAnom.dboperation.MyOperations.ReadData(MyOperations.java:58)
org.apache.jsp.attacker_005flogin_005fsave_jsp._jspService(attacker_005flogin_005fsave_jsp.java:133)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

root cause
<eval>:2:2321421 java.lang.RuntimeException: Method code too large!
jdk.nashorn.internal.runtime.ECMAException.create(ECMAException.java:113)
jdk.nashorn.internal.scripts.Script$Recompilation$1174$2321360II$\^eval\_.PgQuery$invoke_ii(<eval>:2)
jdk.nashorn.internal.scripts.Script$Recompilation$1172$3313153AI$\^eval\_.:scopeCall-2(<eval>)
jdk.nashorn.internal.scripts.Script$Recompilation$1172$3313153AI$\^eval\_.PgQuery$asm$Oc(<eval>:13)
jdk.nashorn.internal.scripts.Script$Recompilation$1159$3314970II$\^eval\_.PgQuery$asm$Pc(<eval>:13)
jdk.nashorn.internal.scripts.Script$Recompilation$1158$2960989AI$\^eval\_.PgQuery$asm$Ah(<eval>:9)
jdk.nashorn.internal.scripts.Script$Recompilation$1157$2972086II$\^eval\_.PgQuery$asm$ji(<eval>:9)
jdk.nashorn.internal.scripts.Script$Recompilation$1156$3374026AAA$\^eval\_.PgQuery$asm$kl(<eval>:14)
jdk.nashorn.internal.scripts.Script$Recompilation$1155$73AA$\^function\_.L:1$dynCall_iii_35(<function>:3)
jdk.nashorn.internal.scripts.Script$Recompilation$1153$118A$\^function\_.L:1$raw_parse(<function>:7)
jdk.nashorn.internal.scripts.Script$Recompilation$1148$419A$\^eval\_.PgQuery$parse(<eval>:2)
jdk.nashorn.internal.scripts.Script$Recompilation$1147$850A$signature.signature_hash(file:/C:/Users/RIT/Desktop/post/web/js/signature.js:41)
jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:639)
jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)
jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)
jdk.nashorn.api.scripting.ScriptObjectMirror.callMember(ScriptObjectMirror.java:199)
jdk.nashorn.api.scripting.NashornScriptEngine.invokeImpl(NashornScriptEngine.java:383)
jdk.nashorn.api.scripting.NashornScriptEngine.invokeFunction(NashornScriptEngine.java:190)
com.DetAnom.dboperation.MyOperations.ReadData(MyOperations.java:58)
org.apache.jsp.attacker_005flogin_005fsave_jsp._jspService(attacker_005flogin_005fsave_jsp.java:133)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

How to solve this problem?
Any advice?

Answers: