Closed GoogleCodeExporter closed 8 years ago
The problem goes away by adding a synchronization lock :
changing
org.mockito.internal.verification.RegisteredInvocations
from
public List<Invocation> getAll() {
return ListUtil.filter(new LinkedList<Invocation>(invocations), new RemoveToString());
}
to
public List<Invocation> getAll() {
synchronized (invocations) {
return ListUtil.filter(new LinkedList<Invocation>(invocations), new RemoveToString());
}
}
Original comment by edoco...@gmail.com
on 29 Feb 2012 at 2:54
please also note that even though the invocations field in
RegisteredInvocations is a synchronized list:
public class RegisteredInvocations implements Serializable {
...
private final List<Invocation> invocations = Collections.synchronizedList(new LinkedList<Invocation>());
any iterations on it still must be synchronized
http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#synchronized
List%28java.util.List%29
I suppose my proposed patch could be refined by synchronizing only in creating
the new list copy, then releasing the lock and then returning the filtered
copy.
Original comment by edoco...@gmail.com
on 29 Feb 2012 at 3:25
public List<Invocation> getAll() {
LinkedList<Invocation> invocationsCopy;
synchronized (invocations) {
invocationsCopy = new LinkedList<Invocation>(invocations);
}
return ListUtil.filter(invocationsCopy, new RemoveToString());
}
Original comment by edoco...@gmail.com
on 29 Feb 2012 at 3:27
Well spotted. Thx a lot for the report and the possible fix.
Original comment by brice.du...@gmail.com
on 29 Feb 2012 at 4:50
I just added this fix in the attached patch.
Original comment by Jose.Pau...@gmail.com
on 7 Mar 2012 at 7:56
Attachments:
@edocomar With José and Eric we tried to reproduce with your test, but we
didn't success, we had different OS and JVMs, tried different values in your
test.
Do you have an actual values that would make this issue visible.
However we all definitely agree on the proposed fix.
Original comment by brice.du...@gmail.com
on 9 Mar 2012 at 4:38
Hi
the values I posted made the ConcurrentModificationException happen for me.
I just tried on a Mac 10.7.4, java.runtime.version=1.6.0_29-b11-402-11D50b
and no matter what values I use the CME never occurs.
maybe it's down to how the real threading occurs, how many cpus/cores.
Original comment by edoco...@gmail.com
on 9 Mar 2012 at 5:22
Mac 10.7.3
Original comment by edoco...@gmail.com
on 9 Mar 2012 at 5:22
Yeah I got the very same version of OSX and JVM. And I have a dual core
machine. However it is noteworthy that we didn't test it on a RHEL and
especially on an IBM JVM. That would be awesome if you could verify that as we
don't have acces to an IBM JVM.
Original comment by brice.du...@gmail.com
on 9 Mar 2012 at 5:30
I had verified it on RHEL when I posted ... will try again just for making sure.
Original comment by edoco...@gmail.com
on 9 Mar 2012 at 8:31
ok, I tried again I can confirm that
without the patch my test fails with the CME above and with the patch, my test
passes.
java.fullversion=JRE 1.6.0 IBM J9 2.6 Linux amd64-64 20111113_94967 (JIT
enabled, AOT enabled)
Linux 2.6.32-220.4.2.el6.x86_64 #1 SMP Mon Feb 6 16:39:28 EST 2012 x86_64
x86_64 x86_64 GNU/Linux
Original comment by edoco...@gmail.com
on 9 Mar 2012 at 9:31
OK, great, thank you very much for the time you spent validating the issue.
We can comment the test with these details now, as it was not reproductible
under other circumstances.
Original comment by brice.du...@gmail.com
on 9 Mar 2012 at 9:47
Original comment by szcze...@gmail.com
on 13 May 2012 at 3:37
Original comment by szcze...@gmail.com
on 3 Jun 2012 at 2:06
Original issue reported on code.google.com by
edoco...@gmail.com
on 29 Feb 2012 at 2:22