【发布时间】:2014-10-04 05:22:14
【问题描述】:
如果有的话,我可以做些什么来阻止 Nashorn 一直抛出 ArrayIndexOutOfBoundsException?
这个看似微不足道且正确(这里没有错误)的代码 sn-p 导致 Nashorn 异常:
文件 test.js:
var test;
(function (test) {
(function (renderer) {
var posts = {
0: null,
1: null,
2: null,
3: null // comment out this line --> no exception thrown
};
})(test.renderer = {}); // comment out 'test.renderer = ' --> no exception thrown
})(test = {});
然后像这样运行脚本:/usr/lib/jvm/java-8-oracle/bin/jjs test.js
结果:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at jdk.nashorn.internal.runtime.AccessorProperty.initGetterSetter(AccessorProperty.java:271)
at jdk.nashorn.internal.runtime.AccessorProperty.<init>(AccessorProperty.java:250)
at jdk.nashorn.internal.runtime.SetMethodCreator.createNewFieldSetter(SetMethodCreator.java:166)
at jdk.nashorn.internal.runtime.SetMethodCreator.createNewPropertySetter(SetMethodCreator.java:156)
at jdk.nashorn.internal.runtime.SetMethodCreator.createSetMethod(SetMethodCreator.java:122)
at jdk.nashorn.internal.runtime.SetMethodCreator.createGuardedInvocation(SetMethodCreator.java:78)
at jdk.nashorn.internal.runtime.ScriptObject.findSetMethod(ScriptObject.java:1911)
at jdk.nashorn.internal.runtime.ScriptObject.lookup(ScriptObject.java:1632)
at jdk.nashorn.internal.runtime.linker.NashornLinker.getGuardedInvocation(NashornLinker.java:96)
at jdk.internal.dynalink.support.CompositeTypeBasedGuardingDynamicLinker.getGuardedInvocation(CompositeTypeBasedGuardingDynamicLinker.java:176)
at jdk.internal.dynalink.support.CompositeGuardingDynamicLinker.getGuardedInvocation(CompositeGuardingDynamicLinker.java:124)
at jdk.internal.dynalink.support.LinkerServicesImpl.getGuardedInvocation(LinkerServicesImpl.java:144)
at jdk.internal.dynalink.DynamicLinker.relink(DynamicLinker.java:232)
at jdk.nashorn.internal.scripts.Script$test.L:2(test.js:3)
at jdk.nashorn.internal.scripts.Script$test.runScript(test.js:2)
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:535)
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:209)
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:378)
at jdk.nashorn.tools.Shell.apply(Shell.java:383)
at jdk.nashorn.tools.Shell.runScripts(Shell.java:312)
at jdk.nashorn.tools.Shell.run(Shell.java:168)
at jdk.nashorn.tools.Shell.main(Shell.java:132)
at jdk.nashorn.tools.Shell.main(Shell.java:111)
当我通过脚本引擎在 JVM 中运行文件时也会发生这种情况。
背景:我正在尝试在 Nashorn 中运行 TypeScript 生成的代码。上面的代码 sn -p 是简化的 TypeScript 编译器输出。
操作系统:Linux Mint 17,64 位。 Java版本:
$ java -version
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
【问题讨论】:
-
你能发布 java -version 的输出吗?我注意到 Nashorn 正在随着 JDK 1.8 的各种次要版本而改变,所以它可能会有所不同。
-
@DavidP.Caldwell 是的,我忘记了,完成(将其附加到问题中)。
-
嗨@Jarrod Robertson,实际上这不是stackoverflow.com/questions/32568261/… 的副本。这个问题是关于 Nashorn always 抛出
ArrayIndexOutOfBoundsException即使对于 正确 代码 - 原因是 Nashorn 中的一个错误。
标签: java javascript nashorn