Use iterator when removing to avoid ConcurrentModificationException -

fixes #652
This commit is contained in:
Tom Morris 2013-08-17 13:45:22 -04:00
parent 3315136681
commit e93bfa798e

View File

@ -35,6 +35,7 @@ package com.google.refine;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
@ -109,10 +110,11 @@ public class InterProjectModel {
public void flushJoinsInvolvingProject(long projectID) { public void flushJoinsInvolvingProject(long projectID) {
synchronized (_joins) { synchronized (_joins) {
for (Entry<String, ProjectJoin> entry : _joins.entrySet()) { for (Iterator<Entry<String, ProjectJoin>> it = _joins.entrySet().iterator(); it.hasNext();) {
Entry<String, ProjectJoin> entry = it.next();
ProjectJoin join = entry.getValue(); ProjectJoin join = entry.getValue();
if (join.fromProjectID == projectID || join.toProjectID == projectID) { if (join.fromProjectID == projectID || join.toProjectID == projectID) {
_joins.remove(entry.getKey()); it.remove();
} }
} }
} }
@ -120,11 +122,12 @@ public class InterProjectModel {
public void flushJoinsInvolvingProjectColumn(long projectID, String columnName) { public void flushJoinsInvolvingProjectColumn(long projectID, String columnName) {
synchronized (_joins) { synchronized (_joins) {
for (Entry<String, ProjectJoin> entry : _joins.entrySet()) { for (Iterator<Entry<String, ProjectJoin>> it = _joins.entrySet().iterator(); it.hasNext();) {
Entry<String, ProjectJoin> entry = it.next();
ProjectJoin join = entry.getValue(); ProjectJoin join = entry.getValue();
if (join.fromProjectID == projectID && join.fromProjectColumnName.equals(columnName) || if (join.fromProjectID == projectID && join.fromProjectColumnName.equals(columnName) ||
join.toProjectID == projectID && join.toProjectColumnName.equals(columnName)) { join.toProjectID == projectID && join.toProjectColumnName.equals(columnName)) {
_joins.remove(entry.getKey()); it.remove();
} }
} }
} }