Caused by: java.util.ConcurrentModificationException java调试error修复

Caused by: java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:909) ~[?:1.8.0_171]

at java.util.ArrayList$Itr.next(ArrayList.java:859) ~[?:1.8.0_171]

public void removeUnchangeFeatures(List<WmFeatureRelation> relations,List<Long> featureStatus1,List<Long> featureStatus2){
    Map<Long,WmFeatureRelation> relationMap = Maps.uniqueIndex(relations,WmFeatureRelation::getFeatureGpId);
    for(long feature1:featureStatus1){
        if(relationMap.get(feature1).getStatus()==1)featureStatus1.remove(feature1);
    }
    for(long feature2:featureStatus2){
        if(relationMap.get(feature2).getStatus()==2)featureStatus2.remove(feature2);
    }
}

我在两个循环中,对迭代对象featureStatus进行了更改,造成异常,正常情况下,被迭代对象在迭代时时不可以更改的。

public void removeUnchangeFeatures(List<WmFeatureRelation> relations,List<Long> featureStatus1,List<Long> featureStatus2){
    Map<Long,WmFeatureRelation> relationMap = Maps.uniqueIndex(relations,WmFeatureRelation::getFeatureId);
    List<Long> removeFeature1 = new ArrayList<>();
    List<Long> removeFeature2 = new ArrayList<>();
    for(long feature1:featureStatus1){
        if(relationMap.get(feature1).getStatus()==1)removeFeature1.add(feature1);
    }
    featureStatus1.removeAll(removeFeature1);
    for(long feature2:featureStatus2){
        if(relationMap.get(feature2).getStatus()==2)removeFeature2.add(feature2);
    }
    featureStatus2.removeAll(removeFeature2);
}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页