mockito: Unexpected error (Mockito can only mock non-private & non-final classes.) in version 2.24.0

Hi,

Since version 2.24.0 I got the error “Mockito can only mock non-private & non-final classes.”. Reverting back to Mockito 2.23.4 resolves the problem.

Stacktrace Underlying exception : java.lang.IllegalArgumentException: Could not create type at nl.tkp.ddw.pensioenaangifte.test.model.unittesten.AanleveringFilteringStepDefinitions.setup(AanleveringFilteringStepDefinitions.java:43) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at cucumber.runtime.Utils$1.call(Utils.java:26) at cucumber.runtime.Timeout.timeout(Timeout.java:16) at cucumber.runtime.Utils.invoke(Utils.java:20) at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:60) at cucumber.runner.HookDefinitionMatch.runStep(HookDefinitionMatch.java:16) at cucumber.runner.TestStep.executeStep(TestStep.java:63) at cucumber.runner.TestStep.run(TestStep.java:49) at cucumber.runner.TestCase.run(TestCase.java:40) at cucumber.runner.Runner.runPickle(Runner.java:40) at cucumber.runtime.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:146) at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:68) at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:23) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:73) at cucumber.api.junit.Cucumber.runChild(Cucumber.java:124) at cucumber.api.junit.Cucumber.runChild(Cucumber.java:65) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at cucumber.api.junit.Cucumber$1.evaluate(Cucumber.java:133) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58) at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38) at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62) at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:32) at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93) at com.sun.proxy.$Proxy2.processTestClass(Unknown Source) at org.gradle.api.internal.tasks.testing.worker.TestWorker.processTestClass(TestWorker.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:35) at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24) at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:175) at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:157) at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:404) at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63) at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalArgumentException: Could not create type at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:154) at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:365) at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:174) at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:376) at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32) at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71) at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42) at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25) at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35) at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62) at org.mockito.Mockito.mock(Mockito.java:1896) at org.mockito.internal.configuration.MockAnnotationProcessor.processAnnotationForMock(MockAnnotationProcessor.java:44) at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:19) at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:16) at org.mockito.internal.configuration.IndependentAnnotationEngine.createMockFor(IndependentAnnotationEngine.java:38) at org.mockito.internal.configuration.IndependentAnnotationEngine.process(IndependentAnnotationEngine.java:62) at org.mockito.internal.configuration.InjectingAnnotationEngine.processIndependentAnnotations(InjectingAnnotationEngine.java:49) at org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAnnotationEngine.java:41) at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:69) ... 63 more Caused by: java.lang.NoSuchMethodError: net.bytebuddy.dynamic.loading.MultipleParentClassLoader$Builder.appendMostSpecific(Ljava/util/Collection;)Lnet/bytebuddy/dynamic/loading/MultipleParentClassLoader$Builder; at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:83) at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:37) at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:34) at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:152) ... 81 more

Versioninfo Java: 1.8 JVM vendor name: Oracle Corporation JVM vendor version: 25.191-b12 JVM name: Java HotSpot™ 64-Bit Server VM JVM version: 1.8.0_191-b12 JVM info: mixed mode OS name: Mac OS X OS version: 10.13.6 Mockito-core: 2.24.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 32
  • Comments: 81 (31 by maintainers)

Commits related to this issue

Most upvoted comments

Since quite some people have the same issue, i’ve reopened the issue.

I am also getting the same error. Reverting back to 2.23.+ fixes the issue.

Same issue here. Same goes for 2.25.0.

Reverting to 2.23.0 solves the problem.

Seems like you are loading the wrong version of ByteBuddy. What version are you using?

On Mon, 4 Feb 2019, 10:49 Taher, notifications@github.com wrote:

I am also getting the same error. Reverting back to 2.23.+ fixes the issue.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mockito/mockito/issues/1606#issuecomment-460203942, or mute the thread https://github.com/notifications/unsubscribe-auth/AFrDb00_6nD1ZzQkmmEe6lbYHNFnz_8Yks5vKBBTgaJpZM4ag8uJ .

I am still getting this issue with Mockito 3.0.0 (and mockito-android) when running Android instrumentation tests:

org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class com.(...)._MyClass_.

Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.

IMPORTANT INFORMATION FOR ANDROID USERS:

The regular Byte Buddy mock makers cannot generate code on an Android VM!
To resolve this, please use the 'mockito-android' dependency for your application:
http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22mockito-android%22%20g%3A%22org.mockito%22

Java               : 0.9
JVM vendor name    : The Android Project
JVM vendor version : 2.1.0
JVM name           : Dalvik
JVM version        : 0.9
JVM info           : null
OS name            : Linux
OS version         : 3.18.71-g7dfaee7f928


Underlying exception : java.lang.IllegalArgumentException: Could not create type
at _com.(...).MyTest_.setUp(MyTest.java:44)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
(...)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:392)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2074)
Caused by: java.lang.IllegalArgumentException: Could not create type
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:154)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:365)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:174)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:376)
at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32)
at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71)
at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42)
at org.mockito.android.internal.creation.AndroidByteBuddyMockMaker.createMock(AndroidByteBuddyMockMaker.java:39)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:63)
at org.mockito.Mockito.mock(Mockito.java:1908)
at org.mockito.internal.configuration.MockAnnotationProcessor.processAnnotationForMock(MockAnnotationProcessor.java:44)
at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:19)
at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:16)
at org.mockito.internal.configuration.IndependentAnnotationEngine.createMockFor(IndependentAnnotationEngine.java:38)
at org.mockito.internal.configuration.IndependentAnnotationEngine.process(IndependentAnnotationEngine.java:62)
at org.mockito.internal.configuration.InjectingAnnotationEngine.processIndependentAnnotations(InjectingAnnotationEngine.java:49)
at org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAnnotationEngine.java:41)
at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:69)
... 30 more
Caused by: java.lang.NoSuchFieldError: No instance field targetApiLevel of type I in class Lcom/android/dx/dex/DexOptions; or its superclasses (declaration of 'com.android.dx.dex.DexOptions' appears in /data/app/com.teamwork.projects.data.test-WeFv56g4F9J4rFDV8asMpg==/base.apk)
at net.bytebuddy.android.AndroidClassLoadingStrategy$DexProcessor$ForSdkCompiler.makeDefault(AndroidClassLoadingStrategy.java:216)
at net.bytebuddy.android.AndroidClassLoadingStrategy$Injecting.<init>(AndroidClassLoadingStrategy.java:387)
at org.mockito.android.internal.creation.AndroidLoadingStrategy.resolveStrategy(AndroidLoadingStrategy.java:39)
at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:173)
at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:37)
at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:34)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:152)
... 48 more

That version is too low. Mockito depends on ByteBuddy 1.9.7: https://github.com/mockito/mockito/blob/aacacb156166b54b7eba3dfe03dd7bacda54c8d8/gradle/dependencies.gradle#L7 Also shown in the pom: http://central.maven.org/maven2/org/mockito/mockito-core/2.24.0/mockito-core-2.24.0.pom It seems like your project setup does not correctly resolve dependency mismatches.

I think I may have found the culprit: the newer Dexmaker version MockK is using. I’ve managed to get rid of the issue in my project with the latest version of the two libs by doing this:

androidTestImplementation("org.mockito:mockito-android:3.2.4")
androidTestImplementation("io.mockk:mockk-android:1.9.3") {
      exclude module: 'dexmaker'
}
androidTestImplementation "com.linkedin.dexmaker:dexmaker:2.12.1" // newer versions break Mockito

Thank you very much.

resolutionStrategy { force(“com.linkedin.dexmaker:dexmaker:2.12.1”) }

My colleague run into the same issue after recent upgrade to ‘mockito-core’, version: ‘2.25.0’ ‘powermock-api-mockito2’, version: ‘2.0.0’ ‘powermock-module-junit4’, version: ‘2.0.0’.

Downgrading mockito-core to 2.23.0 helped to solve it. Strangely, it happens only running tests individually from IDEA, but they work fine running via Gradle script. Also, I was not able to reproduce it on my machine, though we have very similar environment setups.

Error message:

org.mockito.exceptions.base.MockitoException: Mockito cannot mock this class: class com.fasterxml.jackson.databind.ObjectMapper.

Mockito can only mock non-private & non-final classes. If you’re not sure why you’re getting this error, please report to the mailing list.

Java : 1.8 JVM vendor name : Oracle Corporation JVM vendor version : 25.191-b12 JVM name : Java HotSpot™ 64-Bit Server VM JVM version : 1.8.0_191-b12 JVM info : mixed mode OS name : Windows 10 OS version : 10.0

Underlying exception : java.lang.IllegalArgumentException: Could not create type

I would reopen this as an actual bug since 2.23.0 version doesn’t have this issue and the lib should handle gracefully its own dependencies like this one.

Had the same issue even though we never set bytebuddy as dependency somewhere. Setting bytebuddy dependency explicitly at gradle fixed it for me.

I think I may have found the culprit: the newer Dexmaker version MockK is using. I’ve managed to get rid of the issue in my project with the latest version of the two libs by doing this:

androidTestImplementation("org.mockito:mockito-android:3.2.4")
androidTestImplementation("io.mockk:mockk-android:1.9.3") {
      exclude module: 'dexmaker'
}
androidTestImplementation "com.linkedin.dexmaker:dexmaker:2.12.1" // newer versions break Mockito

I have the same problem with 2.27.0, reverting back to 2.23.4 works.

Interface that Mockito is unable to mock


import java.util.Set;

import br.com.senior.platform.authorization.UserNotificationPriority;
import br.com.senior.platform.authorization.model.ResourceIntegration;

public interface NotifyResourceIntegration {

    boolean notifyOnError(Set<ResourceIntegration> allResources, Throwable ex, String tenant);

    void notifyUser(UserNotificationPriority priority, String content, String tenant);
}

Full stack trace

org.mockito.exceptions.base.MockitoException: 
Mockito cannot mock this class: interface br.com.senior.platform.authorization.service.notification.NotifyResourceIntegration.

Mockito can only mock non-private & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.


Java               : 11
JVM vendor name    : Oracle Corporation
JVM vendor version : 11.0.2+9
JVM name           : OpenJDK 64-Bit Server VM
JVM version        : 11.0.2+9
JVM info           : mixed mode
OS name            : Windows 10
OS version         : 10.0


Underlying exception : java.lang.IllegalArgumentException: Could not create type

	at br.com.senior.platform.authorization.service.notification.NotifyServiceImplTest.setUp(NotifyServiceImplTest.java:38)
	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.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.IllegalArgumentException: Could not create type
	at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:154)
	at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:365)
	at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:174)
	at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:376)
	at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32)
	at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMockType(SubclassByteBuddyMockMaker.java:71)
	at org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:42)
	at org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25)
	at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
	at org.mockito.internal.MockitoCore.mock(MockitoCore.java:62)
	at org.mockito.Mockito.mock(Mockito.java:1907)
	at org.mockito.internal.configuration.MockAnnotationProcessor.processAnnotationForMock(MockAnnotationProcessor.java:44)
	at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:19)
	at org.mockito.internal.configuration.MockAnnotationProcessor.process(MockAnnotationProcessor.java:16)
	at org.mockito.internal.configuration.IndependentAnnotationEngine.createMockFor(IndependentAnnotationEngine.java:38)
	at org.mockito.internal.configuration.IndependentAnnotationEngine.process(IndependentAnnotationEngine.java:62)
	at org.mockito.internal.configuration.InjectingAnnotationEngine.processIndependentAnnotations(InjectingAnnotationEngine.java:49)
	at org.mockito.internal.configuration.InjectingAnnotationEngine.process(InjectingAnnotationEngine.java:41)
	at org.mockito.MockitoAnnotations.initMocks(MockitoAnnotations.java:69)
	... 23 more
Caused by: java.lang.NoSuchMethodError: net.bytebuddy.dynamic.loading.MultipleParentClassLoader$Builder.appendMostSpecific(Ljava/util/Collection;)Lnet/bytebuddy/dynamic/loading/MultipleParentClassLoader$Builder;
	at org.mockito.internal.creation.bytebuddy.SubclassBytecodeGenerator.mockClass(SubclassBytecodeGenerator.java:83)
	at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:37)
	at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator$1.call(TypeCachingBytecodeGenerator.java:34)
	at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:152)
	... 41 more

@TimvdLippe @raphw I was able to solve this issue. I noticed that java 11 does not contain the JAXB APIs. So I included them as dependencies in pom.

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2.11</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.2.11</version>
</dependency>
<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2.11</version>
</dependency>
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>

Thanks for your help.

As explained in my issue #1671 we have the same problem (sorry for the duplicate, I hadn’t seen this one). After investigation, it seems that we have 2 ByteBuddy. The first one is from hibernate-core-5.4.1 and is released byte-buddy 1.9.5 The second one is from mockito-core-2.25.1 and is released byte-buddy 1.9.7

For some reasons, it’s the byte-buddy 1.9.5 from hibernate dependency that is used by mockito.

By exluding byte-buddy from hibernate dependency, we can fix the problem, but I’m not sure that we will not have any side effect on hibernate 😕

<dependency>
	<groupId>org.hibernate</groupId>
	<artifactId>hibernate-core</artifactId>
	<version>5.4.1</version>
	<exclusions>
		<exclusion>
			<artifactId>byte-buddy</artifactId>
			<groupId>net.bytebuddy</groupId>
		</exclusion>
	</exclusions>
</dependency>

I had to add byte-buddy as well as an explicit dependency to our project. Is it valid behaviour to use byte-buddy during runtime, even though it’s specified as just a compile-time dependency of mockito?

Adding bytebuddy as a dependency did fix the problem. I would think Gradle manages this dependency himself.

Anyway, thanks for the help!

In Eclipse make sure to add as external library byte buddy. Ctrl + right click on project > Java Build Path > Libraries > Add external JARS > byte-buddy-1.**.*.jar This worked for me if you want to debug your Junit tests in Eclipse

As explained in my issue #1671 we have the same problem (sorry for the duplicate, I hadn’t seen this one). After investigation, it seems that we have 2 ByteBuddy. The first one is from hibernate-core-5.4.1 and is released byte-buddy 1.9.5 The second one is from mockito-core-2.25.1 and is released byte-buddy 1.9.7

For some reasons, it’s the byte-buddy 1.9.5 from hibernate dependency that is used by mockito.

By exluding byte-buddy from hibernate dependency, we can fix the problem, but I’m not sure that we will not have any side effect on hibernate 😕

<dependency>
	<groupId>org.hibernate</groupId>
	<artifactId>hibernate-core</artifactId>
	<version>5.4.1</version>
	<exclusions>
		<exclusion>
			<artifactId>byte-buddy</artifactId>
			<groupId>net.bytebuddy</groupId>
		</exclusion>
	</exclusions>
</dependency>

This worked for me. I added byte-buddy and byte-buddy-agent dependencies to my pom file in the version 1.9.7.

It was like the following:

                <dependency>
			<groupId>net.bytebuddy</groupId>
			<artifactId>byte-buddy</artifactId>
			<version>1.9.7</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>net.bytebuddy</groupId>
			<artifactId>byte-buddy-agent</artifactId>
			<version>1.9.7</version>
			<scope>test</scope>
		</dependency>

Also, I excluded those dependencies in hibernate-core and hibernate-entitymanager because those dependencies contains the byte-buddy and byte-buddy-agent in a prior version.

We are getting this when attempting to upgrade Spring Boot 2.0.x to 2.1.x.

spring-boot-dependencies specifies the version for ByteBuddy and Mockito:

Spring Boot 2.0:

<byte-buddy.version>1.7.11</byte-buddy.version>
<mockito.version>2.15.0</mockito.version>

Spring Boot 2.1:

<byte-buddy.version>1.9.10</byte-buddy.version>
<mockito.version>2.23.4</mockito.version>

We are using spy on a real class and it is fully public and non-final.

Any version of Mockito newer than 2.15.0 seems to cause this. 2.16.0 uses byte-buddy 1.9.10. Any idea on what I can look for?

Based on the Twitter discussion we had with Maven + Gradle, I will perform an investigation in all possible options

If Hibernate wants 1.9.10 and mockito-core wants 1.9.7, and those versions are not compatible, then I’m not sure what you want the build system to do. It won’t be resolved automatically. Our options:

a) shadowing b) mockito-core bumps to 1.9.10 c) hibernate downgrades to 1.9.7 d) we tell customers to downgrade/force to 1.9.7 and hope that hibernate will work

Some of those options are clearly not viable.