我们在生产中偶尔会遇到与执行SubList操作有关的StackOverFlowError错误。有人以前见过这样的东西,并且知道是什么原因引起的吗?

这是触发错误的被调用的代码:

  FacesContext context = FacesContext.getCurrentInstance();
    String newViewID = context.getViewRoot().getViewId();

    if (newViewID != null) {
     if (breadCrumbs.contains(newViewID)) {
      // Trims the list upon going back to allow for multiple back button requests.
      // This is lightweight and not intended for a complex circular navigation.
      breadCrumbs = breadCrumbs.subList(0, breadCrumbs.indexOf(newViewID) + 1);
     } else {
      breadCrumbs.add(newViewID);
     }
    }

结果 :
Caused By: java.lang.StackOverflowError
 at java.util.SubList$1.<init>(AbstractList.java:688)
 at java.util.SubList.listIterator(AbstractList.java:687)
 at java.util.SubList$1.<init>(AbstractList.java:688)
 at java.util.SubList.listIterator(AbstractList.java:687)
 ...

最佳答案

subList()方法返回一个由原始列表支持的 View 。

根据javadoc:



您正在对列表进行结构更改,因此所有赌注都关闭了-可能发生的任何事情,包括无限递归,似乎正在发生。

10-07 18:52
查看更多