我们在生产环境中偶尔会遇到与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)
...