You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import org.junit.jupiter.api.RepeatedTest;
import org.mockito.Answers;
import java.util.List;
import java.util.stream.IntStream;
import static org.mockito.Mockito.mock;
class ConcurrencyTest {
@RepeatedTest(value = 1000)
void test() {
final Service mock = mock(Service.class, Answers.RETURNS_DEEP_STUBS);
IntStream.range(1, 100).parallel().forEach(i -> mock.doSomething());
}
interface Service {
List<String> doSomething();
}
}
Error: 30/5000 iterations fail with java.util.ConcurrentModificationException
Stacktrace:
Caused by: java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:966)
at java.util.LinkedList$ListItr.next(LinkedList.java:888)
at org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs.deepStub(ReturnsDeepStubs.java:85)
at org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs.answer(ReturnsDeepStubs.java:75)
at org.mockito.Answers.answer(Answers.java:99)
at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:110)
at org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
at org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:34)
at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.doIntercept(MockMethodInterceptor.java:82)
at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.doIntercept(MockMethodInterceptor.java:56)
at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor$DispatcherDefaultingToRealMethod.interceptAbstract(MockMethodInterceptor.java:161)
at ConcurrencyTest$Service$MockitoMock$351714249.doSomething(Unknown Source)
at ConcurrencyTest.lambda$test$0(ConcurrencyTest.java:14)
at java.util.stream.ForEachOps$ForEachOp$OfInt.accept(ForEachOps.java:204)
at java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:110)
at java.util.Spliterator$OfInt.forEachRemaining(Spliterator.java:693)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:290)
at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175)
P.S. If the Answers.RETURNS_DEEP_STUBS is removed, no error occurred.
The text was updated successfully, but these errors were encountered:
LeMikaelF
added a commit
to LeMikaelF/mockito
that referenced
this issue
Oct 12, 2021
Java8 / JUnit5
Mockito version: 3.11.2
Test class:
Error: 30/5000 iterations fail with
java.util.ConcurrentModificationException
Stacktrace:
P.S. If the
Answers.RETURNS_DEEP_STUBS
is removed, no error occurred.The text was updated successfully, but these errors were encountered: