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

mockito on Java 11-ea+21 #1426

Merged
merged 1 commit into from Jul 13, 2018
Merged

Conversation

snazy
Copy link
Contributor

@snazy snazy commented Jul 10, 2018

Fixes #1419

Requires -Dnet.bytebuddy.experimental=true system property to be set to let bytebuddy use asm API version ASM7_EXPERMIENTAL and use the same one in InlineBytecodeGenerator.

Requires -Dnet.bytebuddy.experimental=true system property to be set!
@codecov-io
Copy link

codecov-io commented Jul 10, 2018

Codecov Report

Merging #1426 into release/2.x will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@              Coverage Diff               @@
##             release/2.x    #1426   +/-   ##
==============================================
  Coverage          88.61%   88.61%           
  Complexity          2357     2357           
==============================================
  Files                292      292           
  Lines               5949     5949           
  Branches             719      719           
==============================================
  Hits                5272     5272           
  Misses               497      497           
  Partials             180      180
Impacted Files Coverage Δ Complexity Δ
...al/creation/bytebuddy/InlineBytecodeGenerator.java 92.85% <100%> (ø) 25 <0> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f72147...28fa110. Read the comment docs.

@mockitoguy
Copy link
Member

@raphw, can you comment if this change looks safe to you (e.g. no foreseen use impact):

  • upgrade bytebuddy "1.8.10" -> "1.8.13"
  • upgrade asm "org.ow2.asm:asm:6.1.1" -> "org.ow2.asm:asm:6.2"

@snazy, thank you! I'll wait for a word from @raphw and merge it.

@raphw
Copy link
Member

raphw commented Jul 13, 2018

Yes. Looks good. Would have pushed it myself but currently on vacation. Sorry for the delay.

@mockitoguy
Copy link
Member

Thank you for confirming! I'll merge it.

@mockitoguy mockitoguy merged commit 5fc152d into mockito:release/2.x Jul 13, 2018
@andrepdo
Copy link

andrepdo commented Aug 1, 2018

mockito-core-2.21.0.jar
byte-buddy-1.8.15.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:
Mockito cannot mock this class: interface de.espirit.or.schema.EntityType.

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.172-b11
JVM name : Java HotSpot(TM) 64-Bit Server VM
JVM version : 1.8.0_172-b11
JVM info : mixed mode
OS name : Mac OS X
OS version : 10.13.6

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 de.espirit.or.schema.EntityType, interface java.io.Serializable]

at de.espirit.firstspirit.access.editor.TestEntityAssociate.beforeEach(TestEntityAssociate.java:27)
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.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: org.mockito.exceptions.base.MockitoException: Could not modify all classes [interface de.espirit.or.schema.EntityType, interface java.io.Serializable]
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)
... 23 more
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:

  • Compiled by older versions of scalac
  • Classes that are part of the Android distribution
    at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.triggerRetransformation(InlineBytecodeGenerator.java:164)
    at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.mockClass(InlineBytecodeGenerator.java:141)
    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:69)
    at org.mockito.Mockito.mock(Mockito.java:1895)
    at org.mockito.Mockito.mock(Mockito.java:1804)
    ... 23 more
    Caused by: java.lang.NoSuchFieldError: ASM_API
    at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator$ParameterWritingVisitorWrapper$ParameterAddingClassVisitor.(InlineBytecodeGenerator.java:251)
    at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator$ParameterWritingVisitorWrapper$ParameterAddingClassVisitor.(InlineBytecodeGenerator.java:246)
    at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator$ParameterWritingVisitorWrapper.wrap(InlineBytecodeGenerator.java:242)
    at net.bytebuddy.asm.AsmVisitorWrapper$Compound.wrap(AsmVisitorWrapper.java:645)
    at net.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForInlining$RedefinitionClassVisitor.visit(TypeWriter.java:3672)
    at net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:492)
    at net.bytebuddy.jar.asm.ClassReader.accept(ClassReader.java:355)
    at net.bytebuddy.dynamic.scaffold.TypeWriter$Default$ForInlining.create(TypeWriter.java:2915)
    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:215)
    at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
    at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
    at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
    at sun.instrument.InstrumentationImpl.retransformClasses(InstrumentationImpl.java:144)
    at org.mockito.internal.creation.bytebuddy.InlineBytecodeGenerator.triggerRetransformation(InlineBytecodeGenerator.java:161)
    ... 37 more

@bric3 bric3 added java-11 and removed android labels Mar 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants