- java.util.ConcurrentModification
- java.util.ConcurrentModification
- java.util.ConcurrentModification
- java.util.ConcurrentModification
- java.util.ConcurrentModification
- java.util.ConcurrentModification
- java.util.ConcurrentModification
- java.util.ConcurrentModification
- java.util.ConcurrentModification
- java.util.ConcurrentModification
今天在更新数据时 发现一个错误,错误信息如下
java.util.ConcurrentModificationException: null
at java.util.HashMap$HashIterator.nextNode(HashMap.java:1442)
at java.util.HashMap$KeyIterator.next(HashMap.java:1466)
报错时对应的代码:
Set guideMenuList = smsMenuInfoOld.getFirmGuideMenuList();
Iterator firmGuideInfoIterator = guideMenuList.iterator();
while (firmGuideInfoIterator.hasNext()){
MysqlAgentSmsMenuFirmGuideInfo guideMenu = firmGuideInfoIterator.next();
Iterator messageInfoIterator = guideMenu.getMenuMessageList().iterator();
while (messageInfoIterator.hasNext()){
MysqlAgentSmsMenuMessageInfo smsMenuMessageInfo = messageInfoIterator.next();
guideMenu.getMenuMessageList().remove(smsMenuMessageInfo);
mysqlAgentSmsMenuMessageInfoDao.delete(smsMenuMessageInfo);
}
guideMenuList.remove(guideMenu);
mysqlAgentSmsMenuFirmGuideInfoDao.delete(guideMenu);
}
后来得知set.remove()修改了映射结构 影响了迭代器遍历,需要改为用迭代器删除 则不会出错,将 guideMenuList.remove,guideMenu.getMenuMessageList().remove改为firmGuideInfoIterator.remove,messageInfoIterator.remove后 , 问题解决。
网友评论