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
Provide Java 11 compatibility #1419
Comments
|
asm 6.2 alone does not fix this, neither does upgrading to latest bytebuddy help here. |
Requires -Dnet.bytebuddy.experimental=true system property to be set!
|
mockito-core-2.21.0.jar with org.mockito.plugins.MockMaker "mock-maker-inline" the fix is not working with java 1.8_172 and java 11-ea+24. without "mock-maker-inline" it works org.mockito.exceptions.base.MockitoException: If you're not sure why you're getting this error, please report to the mailing list. Java : 1.8 You are seeing this disclaimer because Mockito is configured to create inlined mocks. Underlying exception : org.mockito.exceptions.base.MockitoException: Could not modify all classes [interface de.espirit.or.schema.EntityType, interface java.io.Serializable] Caused by: org.mockito.exceptions.base.MockitoException: Could not modify all classes [interface de.espirit.or.schema.EntityType, interface java.io.Serializable] This problem should never occur for javac-compiled classes. This problem has been observed for classes that are:
|
|
We are experiencing the same error with Java 11 and inline mocks. |
|
Having similar issue with mockito and Java 11. Unable to mock any class/interface, do we need implement any method for class loading,since defineclass method removed in Java11 ? I even edited my java.policy for assertion exception. Below is the exception: Mockito cannot mock this class: class com.xxx.xxx.toolkit.config.Configuration. Mockito can only mock non-private & non-final classes. Java : 11 Underlying exception : java.lang.IllegalStateException: Error invoking java.lang.invoke.MethodHandles$Lookup#defineClass |
|
Same problem here... |
|
Seeing a related error: |
|
@cstroe Are you sure that you don't have some older byte-buddy version on the classpath? (of course I assume that use you the latest version of Mockito and Byte Buddy provided by it). |
|
@szpak Your intuition is correct. I am using Spring Boot version That fixed my errors. Thank you for the help. |
|
Great to hear. Btw, Spring Boot provides also an easier way to override dependency versions. Here, overriding Mockito would be enough. Btw, AFAIR only Spring Boot 2.1 declared Java 11 compatibility. Therefore, you may want to upgrade to prevent further surprises :). |
this works like a charm, Thank You! |
Anyone has an idea how to do this in pom.xml? |
|
@JiDarwish It's basic maven dependency management ;) <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</test>
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
</exclustions>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.23.4</version>
<scope>test</scope>
</dependency> |
|
@bric3 I did exactly the same, still didn't help :-(
|
|
Ok, adding bytebuddy dep. on top of that helped! |
If your project extend In your Maven file. |
Problem was like this - mockito/mockito#1419
I ran tests with JAva 11 and getting the follwing exception. may be asm 6.2 fixes this?
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: interface de.espirit.firstspirit.access.Language.
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-ea+18
JVM name : Java HotSpot(TM) 64-Bit Server VM
JVM version : 11-ea+18
JVM info : mixed mode
OS name : Linux
OS version : 4.9.0-6-amd64
You are seeing this disclaimer because Mockito is configured to create inlined mocks.
You can learn about inline mocks and their limitations under item #39 of the Mockito class javadoc.
Underlying exception : org.mockito.exceptions.base.MockitoException: Could not modify all classes [interface java.lang.Comparable, interface de.espirit.firstspirit.access.Language]
at de.espirit.firstspirit.generate.TestPluggableUrlCreator.setUp(TestPluggableUrlCreator.java:51)
at jdk.internal.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Caused by: org.mockito.exceptions.base.MockitoException: Could not modify all classes [interface java.lang.Comparable, interface de.espirit.firstspirit.access.Language]
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:137)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:344)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:159)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:353)
Caused by: java.lang.IllegalStateException:
Byte Buddy could not instrument all classes within the mock's type hierarchy
This problem should never occur for javac-compiled classes. This problem has been observed for classes that are:
at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.triggerRetransformation(InlineBytecodeGenerator.java:120)
at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.mockClass(InlineBytecodeGenerator.java:97)
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:137)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:344)
at net.bytebuddy.TypeCache.findOrInsert(TypeCache.java:159)
at net.bytebuddy.TypeCache$WithInlineExpunction.findOrInsert(TypeCache.java:353)
at org.mockito.internal.creation.bytebuddy.TypeCachingBytecodeGenerator.mockClass(TypeCachingBytecodeGenerator.java:32)
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.createMockType(InlineByteBuddyMockMaker.java:200)
at org.mockito.internal.creation.bytebuddy.InlineByteBuddyMockMaker.createMock(InlineByteBuddyMockMaker.java:181)
at org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
at org.mockito.internal.MockitoCore.mock(MockitoCore.java:65)
at org.mockito.Mockito.mock(Mockito.java:1855)
at org.mockito.Mockito.mock(Mockito.java:1787)
Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 55
at net.bytebuddy.jar.asm.ClassReader.(ClassReader.java:166)
at net.bytebuddy.jar.asm.ClassReader.(ClassReader.java:148)
at net.bytebuddy.jar.asm.ClassReader.(ClassReader.java:136)
at net.bytebuddy.utility.OpenedClassReader.of(OpenedClassReader.java:54)
at net.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForInlining.create(TypeWriter.java:2912)
at net.bytebuddy.dynamic.scaffold.TypeWriter$Default.make(TypeWriter.java:1634)
at net.bytebuddy.dynamic.scaffold.inline.RedefinitionDynamicTypeBuilder.make(RedefinitionDynamicTypeBuilder.java:171)
at net.bytebuddy.dynamic.scaffold.inline.AbstractInliningDynamicTypeBuilder.make(AbstractInliningDynamicTypeBuilder.java:92)
at net.bytebuddy.dynamic.DynamicType$Builder$AbstractBase.make(DynamicType.java:2669)
at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.transform(InlineBytecodeGenerator.java:181)
at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:563)
at java.instrument/sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
at java.instrument/sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:167)
at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.triggerRetransformation(InlineBytecodeGenerator.java:117)
The text was updated successfully, but these errors were encountered: