无法追踪堆栈溢出错误的来源
我有一个作为服务运行的 Java 应用程序。运行几天后,我收到堆栈溢出错误。问题是我的源代码中产生错误的堆栈帧不在 printStackTrace 函数报告的错误中。我不知道如何找到问题所在。
这是 printStackTrace 的结果:
java.lang.StackOverflowError
at java.util.LinkedList.listIterator(LinkedList.java:684)
at java.util.SubList$1.<init>(AbstractList.java:700)
at java.util.SubList.listIterator(AbstractList.java:699)
at java.util.SubList$1.<init>(AbstractList.java:700)
at java.util.SubList.listIterator(AbstractList.java:699)
at java.util.SubList$1.<init>(AbstractList.java:700)
at java.util.SubList.listIterator(AbstractList.java:699)
... (this is repeated hundreds of times)
at java.util.SubList.listIterator(AbstractList.java:699)
at java.util.SubList$1.<init>(AbstractList.java:700)
at java.util.SubList.listIterator(AbstractList.java:699)
at java.util.SubList$1.<init>(AbstractList.java:700)
I have a Java application that is working as a service. After several days running I get a stack overflow error. The problem is that the stack frame in my source where the error is being originated is not in the error reported by printStackTrace function. I have no idea about how to find where the problem is.
This is the result of printStackTrace:
java.lang.StackOverflowError
at java.util.LinkedList.listIterator(LinkedList.java:684)
at java.util.SubList$1.<init>(AbstractList.java:700)
at java.util.SubList.listIterator(AbstractList.java:699)
at java.util.SubList$1.<init>(AbstractList.java:700)
at java.util.SubList.listIterator(AbstractList.java:699)
at java.util.SubList$1.<init>(AbstractList.java:700)
at java.util.SubList.listIterator(AbstractList.java:699)
... (this is repeated hundreds of times)
at java.util.SubList.listIterator(AbstractList.java:699)
at java.util.SubList$1.<init>(AbstractList.java:700)
at java.util.SubList.listIterator(AbstractList.java:699)
at java.util.SubList$1.<init>(AbstractList.java:700)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题可以重现如下:
因此,请注意
subList()
的所有调用,并确保它们不会形成如上所述的长子列表链。这样的链是一个递归结构(每个子列表都保留对其父列表的引用),在很长的链上调用listIterator()会导致非常深的递归,从而导致堆栈溢出。
Your problem can be reproduced as follows:
So, pay attention on all invocations of
subList()
and make sure they don't form a long chain of sublists as above.Such a chain is a recursive structure (each sublist keeps a reference to its parent list), and calling
listIterator()
on a very long chain causes a very deep recursion which causes stack overflow.查找
List.subList()
方法的使用 - 这是您可以获得java.util.SubList
实例(具有包可见性的类)的唯一位置。您还可以尝试更新到较新的 Java 版本 - 您的堆栈跟踪与当前版本中列表类的结构不匹配,因此您的问题可能不会在更新的版本上发生(或导致更容易诊断的不同错误)版本。
Look for uses of the
List.subList()
method - that's the only place where you can get an instance ofjava.util.SubList
(a class with package visibility).You could also try upading to a newer Java version - your stack trace doesn't match the structure of the list classes in current versions, so your problem may not occur (or result in a differen error that's easier to diagnose) on a more current version.