java 获取“ArrayIndexOutOfBoundsException:null”且没有堆栈跟踪
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12582370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Getting "ArrayIndexOutOfBoundsException: null" with NO stack trace
提问by Christoph
In our log files we find the following:
在我们的日志文件中,我们发现以下内容:
[2012-09-24 00:09:32.590 +0000UTC] ERROR host server1 [] [] somepackage.someclass [] [Unknown] [V3rAqPaDvvAAAAExEXhdWGyh] [pjsQwTGHzxcAAAE5j4YdGvWV] "ThreadName" Some error happened: java.lang.ArrayIndexOutOfBoundsException: null
There is only this single line, and NO exception stack trace.
只有这一行,没有异常堆栈跟踪。
The try
block in which this exception happens is executing dynamically-generated Java byte-code which was created using javassist.
try
发生此异常的块正在执行使用 javassist 创建的动态生成的 Java 字节码。
I am wondering about two things:
我想知道两件事:
- The
java.lang.ArrayIndexOutOfBoundsException
: null - The missing stack-trace, despite calling the log hook using
logger.error("message", theException)
inside thecatch
block, which ordinarily would lead to a full stack-trace being printed in the log-file.
- 该
java.lang.ArrayIndexOutOfBoundsException
日期null - 丢失的堆栈跟踪,尽管
logger.error("message", theException)
在catch
块内调用了日志钩子,这通常会导致在日志文件中打印完整的堆栈跟踪。
My Questions:
我的问题:
What kind of code can cause a logging output "java.lang.ArrayIndexOutOfBoundsException: null". I try to reproduce this with a test program with no luck. I always get something like "java.lang.ArrayIndexOutOfBoundsException: Index: 3" or similar.
Could the reason for missingstack-trace, be that this code is dynamically generated at runtime, and as such the logger/JVM does not "know" the stack-trace or relevant line number(s)?
什么样的代码会导致日志输出“java.lang.ArrayIndexOutOfBoundsException: null”。我尝试用一个没有运气的测试程序来重现这个。我总是得到类似“java.lang.ArrayIndexOutOfBoundsException:Index:3”或类似的信息。
缺少堆栈跟踪的原因可能是该代码是在运行时动态生成的,因此记录器/JVM 不“知道”堆栈跟踪或相关行号?
We are currently debugging and investigating to get more info, but maybe this sounds familiar to somebody.
我们目前正在调试和调查以获取更多信息,但这对某些人来说可能听起来很熟悉。
回答by Frank Pavageau
String
concatenated with anull
reference might get you such a message:Object obj = null; throw new ArrayIndexOutOfBoundsException("" + obj);
If you're using an Oracle JVM you may want to add
-XX:-OmitStackTraceInFastThrow
as an additional parameter to see if it helps. For some basic exceptions, the JVM reuses the same exception instance after a while, in which case there's no stack trace anymore. This option prevents the reuse, so you always get a stack trace.
String
与null
参考连接可能会给您这样的消息:Object obj = null; throw new ArrayIndexOutOfBoundsException("" + obj);
如果您使用的是 Oracle JVM,您可能需要添加
-XX:-OmitStackTraceInFastThrow
一个附加参数以查看它是否有帮助。对于一些基本的异常,JVM 会在一段时间后重用相同的异常实例,在这种情况下不再有堆栈跟踪。此选项可防止重用,因此您始终可以获得堆栈跟踪。
Edit note: this last could also apply to a recent version of OpenJDK (e.g., 1.8)
编辑说明:最后一个也适用于最新版本的 OpenJDK(例如,1.8)
回答by Volodymyr Kret
I found pretty much the same behavior with disappointing log as shown below:
我发现与令人失望的日志几乎相同的行为,如下所示:
java.lang.ArrayIndexOutOfBoundsException: null
In my case, the problem was in concurrent ArrayList.add calls (two separate threads added elements into shared unsynchronized list). The most interesting thing: firstArrayIndexOutOfBoundsException always had stacktrace and descriptive message, all futureArrayIndexOutOfBoundsExceptions were without stacktrace and message. Tried to reproduce on separate project with plain java threads - no luck (always got full stacktraces etc).
就我而言,问题出在并发 ArrayList.add 调用中(两个单独的线程将元素添加到共享的非同步列表中)。最有趣的事情:第一个ArrayIndexOutOfBoundsException 总是有堆栈跟踪和描述性消息,所有未来的ArrayIndexOutOfBoundsExceptions 都没有堆栈跟踪和消息。试图用普通的 java 线程在单独的项目上重现 - 没有运气(总是有完整的堆栈跟踪等)。
PS. OpenJDK 11, jetty server.
附注。OpenJDK 11,码头服务器。