代码如下
for (Participant participant : subProcessList) {
String def_id = participant.getEntityId();
List list = getParticipantList(service.getPdDefLongIdByStringId(def_id), userInfo.getUserId());
if (null != list){
participant.setParticipantList(list);
} else {
subProcessList.remove(participant);
}
}
在运行这段代码是会出现ConcurrentModificationException这个异常,这个异常出现在checkForComodification()这个方法中,当modCount不等于expectedModCount,则抛出ConcurrentModificationException异常(可以去看一下源码)。
解决办法
修改上面的代码,重新定义一个ArrayList,然后把需要删除的Object放入到这个集合中,然后在进行removeAll非操作。修改如下:
// An highlighted block
List<Participant> removeList = new ArrayList<Participant>();
for (Participant participant : subProcessList) {
String def_id = participant.getEntityId();
List list = getParticipantList(service.getPdDefLongIdByStringId(def_id), userInfo.getUserId());
if (null != list){
participant.setParticipantList(list);
} else {
removeList.add(participant);
}
}
subProcessList.removeAll(removeList);