cloning icon indicating copy to clipboard operation
cloning copied to clipboard

ConcurrentModificationException

Open lyx0224 opened this issue 7 years ago • 4 comments

遍历数组时候的exception ConcurrentModificationException at java.util.ArrayList$ListIterator.next(ArrayList.java:at 573) at com.rits.cloning.FastClonerArrayList.clone()

lyx0224 avatar Jan 18 '18 11:01 lyx0224

I think this is due to some other thread modifying the cloned array list. Cloner doesn't synchronize access (wouldn't be a very good thing to do).

kostaskougios avatar Jan 19 '18 12:01 kostaskougios

@lyx0224 Could be also due to bug in your code, for example, following code fails, because sublist doesn't allow structural modification to the backing list.

List<String> a = new LinkedList<String>();
a.add("1");
a.add("2");
a.add("3");
List<String> b = a.subList(0, 1);
b.add("3");
b.remove(0);
a.remove("3");
List<String> clone = cloner.deepClone(b); // JDK8 throws java.util.ConcurrentModificationException
clone.size(); // with JDK 10 clone gets created, but querying it's size fails with java.util.ConcurrentModificationException

bergmannm avatar May 30 '18 03:05 bergmannm

I believe that this might be fixed. In later Java versions we needed to specially handle AbstractList$Sublist. Can you check with version 1.10.0?

spullara avatar Aug 07 '19 18:08 spullara

Yesterday I had the same Exception because I was cloning a Java Bean with a Logger property in it. (I forgot the static keyword) but crashed all the JVM. I would expect that if it was only a concurrentException it should fail the deepClone method

(lib version 1.9.0)

gfiorini avatar Nov 30 '19 10:11 gfiorini