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

Java 11 Support #150

Closed
raharrison opened this Issue Sep 26, 2018 · 12 comments

Comments

4 participants
@raharrison

raharrison commented Sep 26, 2018

Current Behavior

I get a few issues when running tests with mockk under latest release of Java 11. Probably related to how they keep trying to hide the internal unsafe API's etc.

Most issues seem to be fixed by updating bytebuddy to 1.8.22.

I still do get a few failures generating the below stack trace. Seems it could be linked to the module system somehow?

Stack trace

java.lang.ClassNotFoundException: class common/MyClass (common/MyClass$ByteBuddy$Uahz3t7q$ByteBuddy$DJoKpGa7 is in unnamed module of loader net/bytebuddy/dynamic/loading/ByteArrayClassLoader @66a99584; common/MyClass is in unnamed module of loader 'app')

	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:315)
	at io.mockk.impl.recording.JvmAutoHinter.autoHint(JvmAutoHinter.kt:38)
	at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:31)
	at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:25)
	at io.mockk.MockKDsl.internalEvery(API.kt:93)
	at io.mockk.MockKKt.every(MockK.kt:104)
	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:513)
	at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)
	at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.invokeMethodInExtensionContext(ClassTestDescriptor.java:302)
	at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$synthesizeBeforeEachMethodAdapter$12(ClassTestDescriptor.java:290)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeBeforeEachMethods$2(TestMethodTestDescriptor.java:135)
	at org.junit.jupiter.engine.execution.ThrowableCollector.execute(ThrowableCollector.java:40)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeMethodsOrCallbacksUntilExceptionOccurs(TestMethodTestDescriptor.java:155)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeBeforeEachMethods(TestMethodTestDescriptor.java:134)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:109)
	at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:58)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:113)
	at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:121)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:121)
	at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$2(HierarchicalTestExecutor.java:121)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:177)
	at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
	at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:497)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.lambda$executeRecursively$3(HierarchicalTestExecutor.java:121)
	at org.junit.platform.engine.support.hierarchical.SingleTestExecutor.executeSafely(SingleTestExecutor.java:66)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.executeRecursively(HierarchicalTestExecutor.java:108)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor$NodeExecutor.execute(HierarchicalTestExecutor.java:79)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:55)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:43)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:170)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:154)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:90)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:74)
	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)

Using latest mockk 1.8.7

Minimal reproducible code

class Foo<T : Any> {
    fun foo(): T? = null
}

class Bar {
    @Test
    fun some() {
        val s = mockk<Foo<String>>()
        every { s.foo() } returns "something"
    }
}
@oleksiyp

This comment has been minimized.

Show comment
Hide comment
@oleksiyp

oleksiyp Sep 26, 2018

Collaborator

Thank you for reproducing it. Hope to fix this soon.
Maybe worth to wait for 1.3 Kotlin release as well.
Do you know if it should be released before KotlinConf?

Collaborator

oleksiyp commented Sep 26, 2018

Thank you for reproducing it. Hope to fix this soon.
Maybe worth to wait for 1.3 Kotlin release as well.
Do you know if it should be released before KotlinConf?

oleksiyp added a commit that referenced this issue Sep 26, 2018

@raharrison

This comment has been minimized.

Show comment
Hide comment
@raharrison

raharrison Sep 26, 2018

I am assuming that they might release it there, maybe after the keynote.

There have been a few 1.3 release candidates though, not sure how many breaking changes (if any) it might bring. I expect Java 11 to bring in more issues than 1.3 to be honest.

raharrison commented Sep 26, 2018

I am assuming that they might release it there, maybe after the keynote.

There have been a few 1.3 release candidates though, not sure how many breaking changes (if any) it might bring. I expect Java 11 to bring in more issues than 1.3 to be honest.

@oleksiyp

This comment has been minimized.

Show comment
Hide comment
@oleksiyp

oleksiyp Sep 26, 2018

Collaborator

I switched to newer BB and tests are passing: https://travis-ci.org/mockk/mockk/builds/433754477. This is promising. Now need to check if it is working in Java 11.

Collaborator

oleksiyp commented Sep 26, 2018

I switched to newer BB and tests are passing: https://travis-ci.org/mockk/mockk/builds/433754477. This is promising. Now need to check if it is working in Java 11.

@oleksiyp

This comment has been minimized.

Show comment
Hide comment
@oleksiyp

oleksiyp Sep 26, 2018

Collaborator

Running provided example in JDK11 with BB 1.8.22.
Getting another stack trace:

/usr/java/jdk-11/bin/java ... com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 abc.Bar

java.lang.ClassNotFoundException: class java/lang/String (net/bytebuddy/renamed/java/lang/Object$ByteBuddy$SGxfKBlZ$ByteBuddy$TppQ2n1d is in unnamed module of loader net/bytebuddy/dynamic/loading/ByteArrayClassLoader @b558294; java/lang/String is in module java/base of loader 'bootstrap')

	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:315)
	at io.mockk.impl.recording.JvmAutoHinter.autoHint(JvmAutoHinter.kt:38)
	at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:31)
	at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:25)
	at io.mockk.MockKDsl.internalEvery(API.kt:93)
	at io.mockk.MockKKt.every(MockK.kt:104)
	at abc.Bar.some(Foo.kt:15)
	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.InvokeMethod.evaluate(InvokeMethod.java:17)
	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)


Process finished with exit code 255

Will continue tomorrow

Collaborator

oleksiyp commented Sep 26, 2018

Running provided example in JDK11 with BB 1.8.22.
Getting another stack trace:

/usr/java/jdk-11/bin/java ... com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 abc.Bar

java.lang.ClassNotFoundException: class java/lang/String (net/bytebuddy/renamed/java/lang/Object$ByteBuddy$SGxfKBlZ$ByteBuddy$TppQ2n1d is in unnamed module of loader net/bytebuddy/dynamic/loading/ByteArrayClassLoader @b558294; java/lang/String is in module java/base of loader 'bootstrap')

	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:315)
	at io.mockk.impl.recording.JvmAutoHinter.autoHint(JvmAutoHinter.kt:38)
	at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:31)
	at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:25)
	at io.mockk.MockKDsl.internalEvery(API.kt:93)
	at io.mockk.MockKKt.every(MockK.kt:104)
	at abc.Bar.some(Foo.kt:15)
	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.InvokeMethod.evaluate(InvokeMethod.java:17)
	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)


Process finished with exit code 255

Will continue tomorrow

@pusolito

This comment has been minimized.

Show comment
Hide comment
@pusolito

pusolito Sep 27, 2018

Should a separate task for Kotlin 1.3 support be filed? This is something I’m particularly interested in since I currently use coverify and am moving to Kotlin 1.3.

pusolito commented Sep 27, 2018

Should a separate task for Kotlin 1.3 support be filed? This is something I’m particularly interested in since I currently use coverify and am moving to Kotlin 1.3.

@oleksiyp

This comment has been minimized.

Show comment
Hide comment
@oleksiyp

oleksiyp Sep 27, 2018

Collaborator

@pusolito would be nice if you create a seprate ticket

Seems this error is pretty easy to fix. That's good news. Now provided example is working. I was a bit afraid it will stuck somewhere. I'll do matrix tests and the release it.

Collaborator

oleksiyp commented Sep 27, 2018

@pusolito would be nice if you create a seprate ticket

Seems this error is pretty easy to fix. That's good news. Now provided example is working. I was a bit afraid it will stuck somewhere. I'll do matrix tests and the release it.

oleksiyp added a commit that referenced this issue Sep 27, 2018

@oleksiyp

This comment has been minimized.

Show comment
Hide comment
@oleksiyp

oleksiyp Sep 27, 2018

Collaborator

MockK 1.8.8 released with Java 11 support.
Please check it and report if any issues appear.
Thanks!

Collaborator

oleksiyp commented Sep 27, 2018

MockK 1.8.8 released with Java 11 support.
Please check it and report if any issues appear.
Thanks!

@MrVilkaman

This comment has been minimized.

Show comment
Hide comment
@MrVilkaman

MrVilkaman Sep 27, 2018

Have you version with support kotlin 1.3 and not experimental coroutines ?

unfortunately I have error:
io.mockk.MockKException: Add coroutines support artifact 'org.jetbrains.kotlinx:kotlinx-coroutines-core' to your project

    ext.kotlin_version = '1.3.0-rc-57'
    ext.kotlin_coroutines_version = '0.26.1-eap13'
    compile "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
    testImplementation "io.mockk:mockk:1.8.8"

MrVilkaman commented Sep 27, 2018

Have you version with support kotlin 1.3 and not experimental coroutines ?

unfortunately I have error:
io.mockk.MockKException: Add coroutines support artifact 'org.jetbrains.kotlinx:kotlinx-coroutines-core' to your project

    ext.kotlin_version = '1.3.0-rc-57'
    ext.kotlin_coroutines_version = '0.26.1-eap13'
    compile "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"
    testImplementation "io.mockk:mockk:1.8.8"
@oleksiyp

This comment has been minimized.

Show comment
Hide comment
@oleksiyp

oleksiyp Sep 27, 2018

Collaborator

Not yet

Collaborator

oleksiyp commented Sep 27, 2018

Not yet

@MrVilkaman

This comment has been minimized.

Show comment
Hide comment
@MrVilkaman

MrVilkaman Sep 27, 2018

Can I create new issue about support not experimental coroutines ?

MrVilkaman commented Sep 27, 2018

Can I create new issue about support not experimental coroutines ?

@oleksiyp

This comment has been minimized.

Show comment
Hide comment
@oleksiyp

oleksiyp Sep 27, 2018

Collaborator

Of course, just create Kotlin 1.3 support issue

Collaborator

oleksiyp commented Sep 27, 2018

Of course, just create Kotlin 1.3 support issue

@raharrison

This comment has been minimized.

Show comment
Hide comment
@raharrison

raharrison Sep 27, 2018

Everything seems to work fine on my end. Thanks for quick turnaround!

raharrison commented Sep 27, 2018

Everything seems to work fine on my end. Thanks for quick turnaround!

@raharrison raharrison closed this Sep 27, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment