3回复
2年前
【已结算】ClassLoader.loadClass加载Narhon引擎时报错Nest-host class_info_index 21 has bad constant type【赏金10元】
运行时报错:Caused by: java.lang.ClassFormatError: Nest-host class_info_index 21 has bad constant type in class file jdk/nashorn/internal/codegen/OptimisticTypesPersistence$5
jvm使用的是jdk11,公司针对openjdk11做过修改,但是看这部分源码与openjdk11是一致的。
没有解决思路,所以还没有尝试任务解决方法。
运行代码是:
// 执行表达式
log.info("计算公式控件----执行的表达式为:{}", formula);
//替换中英文括号
formula = formula.replace("(", "(");
formula = formula.replace(")", ")");
Object result;
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("JavaScript");
try {
result = engine.eval(formula);//
} catch (ScriptException e) {
return "0";
}
if (Objects.isNull(result) || !NumberUtils.isParsable(String.valueOf(result))) {
return "0";
}
return String.valueOf(result);
}
报错代码是:engine.eval(formula);
报错栈是:
at java.base/java.lang.ClassLoader.defineClass2(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1109)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:206)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:759)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:680)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:605)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.RecompilableScriptFunctionData.getCompiler(RecompilableScriptFunctionData.java:669)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.RecompilableScriptFunctionData.getCompiler(RecompilableScriptFunctionData.java:650)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.RecompilableScriptFunctionData.compileTypeSpecialization(RecompilableScriptFunctionData.java:726)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.RecompilableScriptFunctionData.getBest(RecompilableScriptFunctionData.java:907)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.getGeneric(ScriptFunctionData.java:402)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.createGenericInvoker(ScriptFunctionData.java:297)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.getGenericInvoker(ScriptFunctionData.java:291)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:638)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527)
at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:456)
at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:413)
at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:409)
at jdk.scripting.nashorn/jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:162)
at java.scripting/javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
1054 阅读