PDA

View Full Version : [FIXED] Store commit/reject changes bug



brom38
22 Jul 2008, 5:37 AM
When I try commit or reject changes for "dirty" Store I recieve java.util.ConcurrentModificationException.


com.extjs.gxt.ui.client.store.Store.java
...
public void rejectChanges() {
for (Record r : modified) { // iterate through "modified" list
r.reject(false); // in this method fire: store.afterReject(this);
}
modified.clear();
}
...
protected void afterReject(Record record) {
modified.remove(record); // change "modified" list !!!!
// in next iteration through "modified" list in rejectChanges() I recieve ConcurrentModificationException
fireStoreEvent(Update, RecordUpdate.REJECT, record);
}

darrellmeyer
22 Jul 2008, 7:27 AM
Fix is in SVN.

tikvar
22 Oct 2009, 4:25 AM
I came across the same issue in Record:


com.extjs.gxt.ui.client.store.Record.java
...
public void reject(boolean silent) {
if (modified != null) {
for (String p : modified.keySet()) {
model.set(p, modified.get(p));
// the call above this line leads (via FieldBinding) to a call to Record.set(p, modified.get(p))
// which changes the modified field and this results in ConcurrentModiificationException
}
}
...
}

public void set(String name, Object value) {
...
if (!modified.containsKey(name)) {
modified.put(name, model.get(name));
} else {
Object origValue = modified.get(name);
if ((origValue == null && value == null)
|| (origValue != null && origValue.equals(value))) {

modified.remove(name);
...
}

}
...
}
To fix the issue, just make a copy of the keyset before iterating over it:

com.extjs.gxt.ui.client.store.Record.java
...
public void reject(boolean silent) {
if (modified != null) {
List<String> modifiedKeys = new ArrayList<String>(modified.keySet());
for (String p : modifiedKeys) {
model.set(p, modified.get(p));
}
}
...
}

darrellmeyer
2 Nov 2009, 9:39 AM
Fixed in trunk. Change will be available in 2.1 release.