Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stackoverflow error when upgrading to v3.5.2 #2011

Closed
jdussouillez opened this issue Aug 20, 2020 · 22 comments · Fixed by #2023
Closed

Stackoverflow error when upgrading to v3.5.2 #2011

jdussouillez opened this issue Aug 20, 2020 · 22 comments · Fixed by #2023

Comments

@jdussouillez
Copy link

jdussouillez commented Aug 20, 2020

I tried to upgrade from Mockito v3.4.6 to v3.5.2 and I'm getting a stackoverflow error (same error with v3.5.0) when running some tests (not all of them, just a few ; even in the same class : some tests pass and others don't).

Stacktrace :

java.lang.StackOverflowError
	at java.base/java.lang.ThreadLocal.get(ThreadLocal.java:163)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.lambda$new$3(InlineByteBuddyMockMaker.java:260)
	at org.mockito.internal.creation.bytebuddy.MockMethodAdvice.handleConstruction(MockMethodAdvice.java:176)
	at org.mockito.internal.creation.bytebuddy.inject.MockMethodDispatcher.handleConstruction(MockMethodDispatcher.java:53)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at java.base/java.lang.ClassCastException.<init>(ClassCastException.java:58)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at java.base/java.lang.ClassCastException.<init>(ClassCastException.java:58)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
        ...

I didn't succeed in reproduce the error in a small project, but I'll spend more time to try and post the sources here when/if I have a reproducible case.

Environment :

  • Mockito v3.5.2
  • JUnit v5.6.2
  • Java :

openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1, mixed mode, sharing)

  • Maven : v3.6.0 (tests are run by the maven-surefire plugin)
@jdussouillez
Copy link
Author

jdussouillez commented Aug 20, 2020

I just discovered that the error happens when I launch all my unit tests in the Maven module, but it's fine if I run the test or the test class only.

$ cd myproject/my-mvn-module-1
$ mvn test
#
# [ERROR]   MyBeanTest.test1 » StackOverflow
#
$ mvn -Dtest=MyBeanTest test
# 
# Tests run: 7, Failures: 0, Errors: 0, Skipped: 0
#
$ mvn -Dtest=MyBeanTest#test1 test
# 
# Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
#

Maven configuration (in the root pom.xml) :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.2</version>
    <configuration>
        <skipTests>${skip.unit.tests}</skipTests>
        <includes>
            <include>**/*Test.java</include>
        </includes>
        <argLine>-Dnet.bytebuddy.experimental=true @{argLine} -Dfile.encoding=${project.reporting.outputEncoding}</argLine>
        <trimStackTrace>false</trimStackTrace>
    </configuration>
</plugin>

@jdussouillez jdussouillez changed the title Stackoverflow error after upgrading to v3.5.2 Stackoverflow error when upgrading to v3.5.2 Aug 20, 2020
@raphw
Copy link
Member

raphw commented Aug 20, 2020

Thanks for reporting. Can you supply an example test case? It looks like an exception is supposed to be thrown but the constructor mocking intercepts its creation where something causes another exception which is again passed to the handler.

Do you mock exceptions somewhere?

Also, could you share the bottom of the stack trace which is where the circularity is introduced.

@cmuchinsky
Copy link

cmuchinsky commented Aug 20, 2020

Seeing the same thing myself, although I don't have a stable reproduction scenario. The same was observed with 3.5.0

@raphw
Copy link
Member

raphw commented Aug 20, 2020

Could you try the latest release to see if the problem still occurs?

@cmuchinsky
Copy link

Sorry I was not clear originally, I saw the problem at first on 3.5.0 but still see it with 3.5.2.

@jdussouillez
Copy link
Author

@raphw

Yes I mock some exceptions in other test classes but the ones who ends with StackoverflowError. I will take some time today or next week to try to reproduce the bug in a small project.

The full stacktrace :

java.lang.StackOverflowError
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.lambda$new$3(InlineByteBuddyMockMaker.java)
	at org.mockito.internal.creation.bytebuddy.MockMethodAdvice.handleConstruction(MockMethodAdvice.java:176)
	at org.mockito.internal.creation.bytebuddy.inject.MockMethodDispatcher.handleConstruction(MockMethodDispatcher.java:53)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at java.base/java.lang.ClassCastException.<init>(ClassCastException.java:58)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at java.base/java.lang.ClassCastException.<init>(ClassCastException.java:58)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at java.base/java.lang.ClassCastException.<init>(ClassCastException.java:58)
	/* [...] */
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at java.base/java.lang.ClassCastException.<init>(ClassCastException.java:58)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at java.base/java.lang.ClassCastException.<init>(ClassCastException.java:58)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	/* end of stacktrace */

@raphw
Copy link
Member

raphw commented Aug 22, 2020

This can't be the full stack trace since it needs to origin somewhere. Maybe it's cut off in the print?

I think I know the problem and tried to fix it. Unfortunately, we have some release issues but you could build release/3.x locally and try if the problem still occurs.

@cheister
Copy link

I'm seeing the same error when trying to go from 3.4.6 to 3.5.0.

java.lang.StackOverflowError
	at org.mockito.internal.creation.bytebuddy.inject.MockMethodDispatcher.isConstructorMock(MockMethodDispatcher.java:57)
	at java.base/java.lang.Exception.<init>(Exception.java)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at org.mockito.exceptions.base.MockitoException.<init>(MockitoException.java:34)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.lambda$new$3(InlineByteBuddyMockMaker.java:273)
	at org.mockito.internal.creation.bytebuddy.MockMethodAdvice.handleConstruction(MockMethodAdvice.java:176)
	at org.mockito.internal.creation.bytebuddy.inject.MockMethodDispatcher.handleConstruction(MockMethodDispatcher.java:69)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at org.mockito.exceptions.base.MockitoException.<init>(MockitoException.java:34)
... 

seems to be related to using a @SPY in the test class, when I change the @SPY to an @mock the error goes away. What seems odd in my case is everything is ok until there are more than 15 tests in the class. 15 tests will pass and any additional tests will fail.

The message of the first exception is Unexpected spy for java.util.AbstractMap on instance of java.util.concurrent.ConcurrentHashMap

@jdussouillez
Copy link
Author

jdussouillez commented Aug 24, 2020

@raphw Same issue with v3.5.5.

Stacktrace :

java.lang.StackOverflowError
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.lambda$new$3(InlineByteBuddyMockMaker.java:273)
	at org.mockito.internal.creation.bytebuddy.MockMethodAdvice.handleConstruction(MockMethodAdvice.java:176)
	at org.mockito.internal.creation.bytebuddy.inject.MockMethodDispatcher.handleConstruction(MockMethodDispatcher.java:69)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at org.mockito.exceptions.base.MockitoException.<init>(MockitoException.java:34)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.lambda$new$3(InlineByteBuddyMockMaker.java:273)
	at org.mockito.internal.creation.bytebuddy.MockMethodAdvice.handleConstruction(MockMethodAdvice.java:176)
	at org.mockito.internal.creation.bytebuddy.inject.MockMethodDispatcher.handleConstruction(MockMethodDispatcher.java:69)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at org.mockito.exceptions.base.MockitoException.<init>(MockitoException.java:34)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.lambda$new$3(InlineByteBuddyMockMaker.java:273)
	at org.mockito.internal.creation.bytebuddy.MockMethodAdvice.handleConstruction(MockMethodAdvice.java:176)
	at org.mockito.internal.creation.bytebuddy.inject.MockMethodDispatcher.handleConstruction(MockMethodDispatcher.java:69)
        [...]
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at org.mockito.exceptions.base.MockitoException.<init>(MockitoException.java:34)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.lambda$new$3(InlineByteBuddyMockMaker.java:273)
	at org.mockito.internal.creation.bytebuddy.MockMethodAdvice.handleConstruction(MockMethodAdvice.java:176)
	at org.mockito.internal.creation.bytebuddy.inject.MockMethodDispatcher.handleConstruction(MockMethodDispatcher.java:69)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at org.mockito.exceptions.base.MockitoException.<init>(MockitoException.java:34)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.lambda$new$3(InlineByteBuddyMockMaker.java:273)
	at org.mockito.internal.creation.bytebuddy.MockMethodAdvice.handleConstruction(MockMethodAdvice.java:176)
	at org.mockito.internal.creation.bytebuddy.inject.MockMethodDispatcher.handleConstruction(MockMethodDispatcher.java:69)
	at java.base/java.lang.Throwable.<init>(Throwable.java)
	at java.base/java.lang.Exception.<init>(Exception.java:66)
	at java.base/java.lang.RuntimeException.<init>(RuntimeException.java:62)
	at org.mockito.exceptions.base.MockitoException.<init>(MockitoException.java:34)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.lambda$new$3(InlineByteBuddyMockMaker.java:273)
	at org.mockito.internal.creation.bytebuddy.MockMethodAdvice.handleConstruction(MockMethodAdvice.java:176)

@raphw
Copy link
Member

raphw commented Aug 24, 2020

@jdussouillez That gets us one step closer but I needed to add an exception for when the error is thrown. Could you build the constructor-dispatch branch locally and see what exception you get in your setup?

@jdussouillez
Copy link
Author

@raphw I installed v3.5.6 from the constructor-dispatch branch : no more errors, all the tests were executed and passed. So I guess commit eaa12bf fixes the issue.

Feel free to ask if you want me to do more tests.

@raphw
Copy link
Member

raphw commented Aug 24, 2020

That's strange since the exception indicates a scenario that should not occur. I merely fixed the recursion.

Can you set a breakppint to see why this happens? What instance is created during spy construction?

@jdussouillez
Copy link
Author

@raphw I didn't succeed in setting breakpoints but I added some logs (before this line).

Patch :

diff --git a/src/main/java/org/mockito/internal/creation/bytebuddy/InlineByteBuddyMockMaker.java b/src/main/java/org/mockito/internal/creation/bytebuddy/InlineByteBuddyMockMaker.java
index 96477f477..6b37ea09e 100644
--- a/src/main/java/org/mockito/internal/creation/bytebuddy/InlineByteBuddyMockMaker.java
+++ b/src/main/java/org/mockito/internal/creation/bytebuddy/InlineByteBuddyMockMaker.java
@@ -265,6 +265,9 @@ public class InlineByteBuddyMockMaker
                         } else if (type.isInstance(spy)) {
                             return spy;
                         } else {
+                            System.out.println("type = " + type.getName());
+                            System.out.println("object = " + object);
+                            System.out.println("spy = " + spy.getClass().getName());
                             isSuspended.set(true);
                             try {
                                 // Unexpected construction of non-spied object

Logs (type is always java.util.AbstractMap):

type = java.util.AbstractMap
object = {}
spy = com.myproject.bean.MyBean1

type = java.util.AbstractMap
object = {}
spy = com.myproject.bean.MyBean2

type = java.util.AbstractMap
object = {}
spy = com.myproject.bean.MyBean3
[...]

@raphw
Copy link
Member

raphw commented Aug 24, 2020

Could you also add a stack trace at the same spot? (Thread.dump())

@jdussouillez
Copy link
Author

jdussouillez commented Aug 25, 2020

Code snippet to dump :

try {
    Thread.dumpStack();
} catch (Throwable t) {
    System.out.println("error while dumping stack: " + t.getMessage());
}
  1. Logs using Thread.dumpStack() after isSuspended.set(true);
type = java.util.AbstractMap
object = {}
spy = com.myproject.bean.MyBeanTest$TestClass
<dump>
java.lang.Exception: Stack trace
	at java.base/java.lang.Thread.dumpStack(Thread.java:1388)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.lambda$new$3(InlineByteBuddyMockMaker.java:272)
	at org.mockito.internal.creation.bytebuddy.MockMethodAdvice.handleConstruction(MockMethodAdvice.java:176)
	at org.mockito.internal.creation.bytebuddy.inject.MockMethodDispatcher.handleConstruction(MockMethodDispatcher.java:69)
	at java.base/java.util.AbstractMap.<init>(AbstractMap.java)
	at java.base/java.util.concurrent.ConcurrentHashMap.<init>(ConcurrentHashMap.java:828)
	at java.base/java.lang.ClassLoader.<init>(ClassLoader.java:333)
	at java.base/java.lang.ClassLoader.<init>(ClassLoader.java:457)
	at java.base/jdk.internal.reflect.DelegatingClassLoader.<init>(ClassDefiner.java:72)
	at java.base/jdk.internal.reflect.ClassDefiner$1.run(ClassDefiner.java:60)
	at java.base/jdk.internal.reflect.ClassDefiner$1.run(ClassDefiner.java:58)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/jdk.internal.reflect.ClassDefiner.defineClass(ClassDefiner.java:57)
	at java.base/jdk.internal.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:400)
	at java.base/jdk.internal.reflect.MethodAccessorGenerator$1.run(MethodAccessorGenerator.java:394)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/jdk.internal.reflect.MethodAccessorGenerator.generate(MethodAccessorGenerator.java:393)
	at java.base/jdk.internal.reflect.MethodAccessorGenerator.generateConstructor(MethodAccessorGenerator.java:92)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:55)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at org.mockito.internal.util.reflection.ReflectionMemberAccessor.lambda$newInstance$0(ReflectionMemberAccessor.java:26)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.lambda$newInstance$4(InlineByteBuddyMockMaker.java:631)
	at org.mockito.internal.util.reflection.ReflectionMemberAccessor.newInstance(ReflectionMemberAccessor.java:26)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.newInstance(InlineByteBuddyMockMaker.java:626)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.doCreateMock(InlineByteBuddyMockMaker.java:373)
	at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.createSpy(InlineByteBuddyMockMaker.java:349)
	at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:44)
	at org.mockito.internal.MockitoCore.mock(MockitoCore.java:61)
	at org.mockito.Mockito.spy(Mockito.java:2033)
	at com.myproject.bean.MyBeanTest.test1(MyBeanTest.java:274)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:686)
	at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
	at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)
	at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)
	at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
	at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:212)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:208)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:137)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:71)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125)
	at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)
	at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)
	at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invokeAllTests(JUnitPlatformProvider.java:150)
	at org.apache.maven.surefire.junitplatform.JUnitPlatformProvider.invoke(JUnitPlatformProvider.java:124)
	at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
	at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
	at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
	at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)
</dump>
  1. Logs using Thread.dumpStack() before isSuspended.set(true);
type = java.util.AbstractMap
object = {}
spy = com.myproject.library.LibraryBean1
<dump>
type = java.lang.Throwable
object = java.lang.Exception
spy = com.myproject.library.LibraryBean1
<dump>
type = java.lang.Throwable
object = java.lang.Exception
spy = com.myproject.library.LibraryBean1

[...]

error while dumping stack: Unexpected spy for java.lang.Throwable on instance of java.lang.Exception
</dump>
error while dumping stack: Unexpected spy for java.lang.Throwable on instance of java.lang.Exception
</dump>
error while dumping stack: Unexpected spy for java.lang.Throwable on instance of java.lang.Exception
</dump>
error while dumping stack: Unexpected spy for java.lang.Throwable on instance of java.lang.Exception
</dump>
error while dumping stack: Unexpected spy for java.lang.Throwable on instance of java.lang.Exception
</dump>

@raphw
Copy link
Member

raphw commented Aug 25, 2020

I thought it would be related to class loading.

I am curious however how you end uo with the reflection member accessor. It should be the instrumentation based one. Are you using the latest build?

@jdussouillez
Copy link
Author

Are you using the latest build?

I pulled the constructor-dispatch branch this morning before giving you the Thread.dumpStack() output. I just switched to branch release/3.x (3.5.6, next 3.5.7), applied my logs and run my tests again : same results.

@raphw
Copy link
Member

raphw commented Aug 25, 2020

Strange, I'll investigate. Could you make sure that you don't have a stale version? You are using mockito-inline or are you configuring the mock maker manually?

@jdussouillez
Copy link
Author

Could you make sure that you don't have a stale version?

I already checked using mvn dependency:tree but it says I'm using 3.5.7 (I'm using the release/3.x branch).
I will try to copy my project, use v3.5.2 and remove code step by step until I can reproduce the bug with only a few files so I can provide you a reproducible example.


You are using mockito-inline or are you configuring the mock maker manually?

I'm using mockito-core :

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-core</artifactId>
    <version>3.5.7</version>
    <scope>test</scope>
</dependency>

And I do not configure anything manually. I just have the src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker config file which contains

mock-maker-inline

@raphw
Copy link
Member

raphw commented Aug 25, 2020

That explains it. You can drop the config and just use the inline artifact which defines the nock maker for you. The member accessor is another plugin which requires manual activation using a similar file if you don't use the other artifact.

@jdussouillez
Copy link
Author

jdussouillez commented Aug 25, 2020

You can drop the config and just use the inline artifact which defines the nock maker for you.

I used mockito-inline v3.5.6, all tests passed but 3. The 3 that fails are new ones (not the ones who failed before) and none of them use Mockito (but all of them are on enums, apparently MyEnum.values() returns an array with null values inside). But they're executed correctly when running them manually, class by class (like I did before)

Do you know how can I generate the inline JAR from the sources ? I can't provide you the logs I added in the source with mockito-inline because the JAR is not generated by ./gradlew -x check clean build.

@jdussouillez
Copy link
Author

@raphw Thank you for the fix and the time spent on this. It works great !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants