Caused by: java.util.ConcurrentModificationException
程序员文章站
2022-06-23 12:50:40
...
Caused by: java.util.ConcurrentModificationException
报错信息
Caused by: java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at com.svw.bnk.peel.formal.FormalPeelUploadResultListAction.getDelpeel(FormalPeelUploadResultListAction.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32)
at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
at com.svw.bnk.peel.formal.FormalPeelUploadResultListAction_$$_javassist_seam_11.getDelpeel(FormalPeelUploadResultListAction_$$_javassist_seam_11.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
at org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
at org.jboss.el.parser.AstBracketSuffix.invoke(AstBracketSuffix.java:63)
at org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
at org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
... 76 more
项目代码:
public void getDelpeel() {
List<Long> list = getDataGridDataStore().getSelectedId();
if (list != null) {
this.formalPeelService.doDelpeel(list);
addMessage(MessageUtil.getMessage("bnk.peel.formalPeel.delpeelSuccess"));
}
@SuppressWarnings("unchecked")
List<FormalPeel> result = (List<FormalPeel>) this.getSession().getAttribute("fpList");
for (Long selectedId : list) {
for (FormalPeel formalPeel : result) {
if (formalPeel.getId().equals(selectedId)) {
result.remove(formalPeel);
}
}
}
this.getSession().removeAttribute("fpList");
// 新的session
this.getSession().setAttribute("fpList", result);
}
导致报错代码如下:
原因:在循环删除时,迭代器的modCount(修改次数)和expectedModCount(期望修改次数)的值不一致。(具体可自行百度)
解决一:迭代器的remove方法中,有一行代码 expectedModCount = modCount; 可以保证在修改之后两个变量的值相等
public void getDelpeel() {
List<Long> list = getDataGridDataStore().getSelectedId();
if (list != null) {
this.formalPeelService.doDelpeel(list);
addMessage(MessageUtil.getMessage("bnk.peel.formalPeel.delpeelSuccess"));
}
@SuppressWarnings("unchecked")
List<FormalPeel> result = (List<FormalPeel>) this.getSession().getAttribute("fpList");
Iterator it = result.iterator();
for (Long selectedId : list) {
while (it.hasNext()){
String s = it.next().toString();
if (s.equals(selectedId)){
it.remove(); // 注意这里
}
}
}
this.getSession().removeAttribute("fpList");
// 新的session
this.getSession().setAttribute("fpList", IteratorUtils.toList(it));
}
解决方法二:该方法是改成索引遍历,但是需要在删除之后保证索引的正常。
public void getDelpeel() {
List<Long> list = getDataGridDataStore().getSelectedId();
if (list != null) {
this.formalPeelService.doDelpeel(list);
addMessage(MessageUtil.getMessage("bnk.peel.formalPeel.delpeelSuccess"));
}
@SuppressWarnings("unchecked")
List<FormalPeel> result = (List<FormalPeel>) this.getSession().getAttribute("fpList");
for (Long selectedId : list) {
for (int i=0; i < result.size(); i++) {
if (result.get(i).getId().equals(selectedId)) {
result.remove(i);
}
}
}
this.getSession().removeAttribute("fpList");
// 新的session
this.getSession().setAttribute("fpList", result);
}
推荐阅读
-
Android Caused by: java.lang.ClassNotFoundException解决办法
-
Caused by SSLError("Can’t connect to HTTPS URL because the SSL module is not available)
-
Caused by: android.os.NetworkOnMainThreadException错误解决办法
-
Caused by: java.lang.reflect.InvocationTargetException
-
安装ssl证书后报错Caused by: java.io.IOException: DerInputStream.getLength(): lengthTag=109, too big.
-
Caused by: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details se
-
Caused by: java.lang.ClassNotFoundException: org.junit.platform.launcher.TestExecutionListener
-
idea启动项目报错Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
-
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '�й���ʱ��' is unrecognized or represents m
-
Caused by SSLError("Can’t connect to HTTPS URL because the SSL module is not available)