- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
如果有的话,我可以做些什么来阻止 Nashorn 一直抛出 ArrayIndexOutOfBoundsException?
这个看似微不足道且正确(此处没有错误)的代码片段导致 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 生成的代码。上面的代码片段是简化的 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 8 中的一个错误。我发布到 Nashorn 邮件列表;这是回复:
I can reproduce the problem with 8u20, however it seems to be fixed in
JDK 9 and JDK8u40. You can download a preview release of 8u40 here:
https://jdk8.java.net/download.html
邮箱:http://mail.openjdk.java.net/pipermail/nashorn-dev/2014-October/003614.html
( 编辑: 8u40 中还有另一个 ArrayIndexOutOfBounds 错误,请在此处阅读更多信息:http://mail.openjdk.java.net/pipermail/nashorn-dev/2015-March/004268.html “无法解析 JSON:{ 0: null, 100: null }”。该问题已在 8u60 中修复。)
关于Java 8 Nashorn ArrayIndexOutOfBoundsException 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26189940/
我创建了一个程序,可以将 10 个长整型数组转换为“电话号码”格式。例如这样:Solution.createPhoneNumber(new int[] {1, 2, 3, 4, 5, 6, 7, 8,
我正在将一个 csv 的每一行与另一个 csv 的每一行进行比较以查找匹配项。然后,我需要添加第二个 csv 中的一些元素和第一个 csv 中的一些元素,并将其写入新文件。它适用于 csv 的第一行,
我正在尝试解析一个字符串以获得 3 个整数,但我有一个强制关闭并且 LogCat 显示:ArrayIndexOutOfBoundExceptions。 这是我的代码的相关部分: dateMod
我已经创建了以下模式来表示用户和一组线程之间的关联,这些线程按他们的最后一条消息排序(用户已经阅读了哪些线程,哪些没有): CREATE TABLE table(user_id bigint, mes
我读取一个文件并将其添加到列表中,然后读取列表并拆分字符串并进行比较并对其进行处理。 我得到这个异常(exception): Exception in thread "main" java.lang.
使用以下代码时,我偶尔会遇到数组索引越界异常。任何线索?数组的大小始终约为 29-30。 logger.info("devicetripmessageinfo size :{}",deviceMess
我遇到了一个问题,但我没有任何线索来解决它! 问题很简单,我从 XSD 文件生成 JAXB 类。 (一个真正复杂的)。但是当编码发生时,我得到一个数组索引超出范围:[在此处插入随机负数] ja
嘿,stackoverflow 社区已经在这个程序上工作了几天,并且被这个错误困扰了一段时间,无法克服它。想知道是否有人可以提供有关正在发生的事情的见解。感谢大家的回复。 这是我运行程序时的输出: 2
我正在尝试制作一个简单的扫雷器,在 n*n 板上埋下 n*n/3 个地雷。地雷用*标记,空格用0标记。(它还不能作为游戏运行:我正在尝试制作扫雷的“答卷”)请注意,我还没有使用过任何有目的的方法。 我
我遇到了这篇文章中描述的类似问题。那里没有答案 - android intro screen error when add to 8 screen, but not error if 4 screen
我在第 66 行遇到错误 c[rowA][colB] = c[rowA][colB] + a[rowA][colA]*b[colA][colB];。我手动检查了索引,只是无法找出索引出错的地方。非常感
我在项目中使用 MessageDigest 计算 md5 签名,但在性能测试期间它抛出 ArrayIndexOutOfBoundsException。 我发现一些帖子表明这是因为 MessageDig
每当我运行代码时,它都会显示线程“main”中的异常 java.lang.ArrayIndexOutOfBoundsException: 0。我确保我的值(value)没有被超出,但它仍然这么说。你们
因此,我尝试按/、- 和空格分割字符串输入,并且在 dateConversion 方法中,我尝试调用字符串数组中的第三项(称为 terms)。如果我的数组只有 2 个元素,我会收到一个错误,我明白原因
这个问题已经有答案了: What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? (25 个回答)
这个问题已经有答案了: What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? (25 个回答)
我在 RegexReverseWords.reverseWords(第 23 行)和 RegexReverseWords.main(第 7 行)的 java.lang.ArrayIndexOutOfB
这个问题已经有答案了: How can I avoid ArrayIndexOutOfBoundsException or IndexOutOfBoundsException? [duplicate]
由于某种原因,我收到 ArrayIndexOutOfBoundsException 错误,我没有尝试访问数组的任何元素,我想做的就是设置大小,并通过引用传递 i.getRGB()。 /* * To
我不知道错误在哪里(插入表)。这是我的代码片段(插入开放寻址哈希表)。线性和双寻址都很好,但是这个(二次函数寻址)就出了问题 Exception in thread "main" java.lang.
我是一名优秀的程序员,十分优秀!