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

java.lang.NoClassDefFoundError: io/mockk/proxy/jvm/advice/jvm/JvmMockKProxyInterceptor #520

Closed
alixwar opened this issue Nov 2, 2020 · 8 comments

Comments

@alixwar
Copy link

alixwar commented Nov 2, 2020

Expected Behavior

Test passing

Current Behavior

Test failed: java.lang.NoClassDefFoundError: io/mockk/proxy/jvm/advice/jvm/JvmMockKProxyInterceptor

Steps to Reproduce

Write a test that executes the following code:

val result = mockkClass(javax.crypto.SecretKey::class)

when you try to evaluate result it crashes.

Context

  • MockK version: 1.10.2
  • OS: Windows 10
  • Kotlin version: 1.4.10
  • JDK version: 11
  • JUnit version: 4.13
  • Type of test: unit test

Failure Logs

"C:\Program Files\Java\jdk-11.0.2\bin\java.exe" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\Android\Android Studio\lib\idea_rt.jar=54882:C:\Program Files\Android\Android Studio\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Android\Android Studio\lib\idea_rt.jar;C:\Program Files\Android\Android Studio\plugins\junit\lib\junit5-rt.jar;C:\Program Files\Android\Android Studio\plugins\junit\lib\junit-rt.jar;C:\Users\Alix\AppData\Local\Android\Sdk\platforms\android-30\data\res;D:\Repositories\android-util\util\build\intermediates\javac\debug\classes;D:\Repositories\android-util\util\build\tmp\kotlin-classes\debugUnitTest;D:\Repositories\android-util\util\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debugUnitTest\R.jar;D:\Repositories\android-util\util\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debugAndroidTest\R.jar;D:\Repositories\android-util\util\build\tmp\kotlin-classes\debugAndroidTest;D:\Repositories\android-util\util\build\generated\res\resValues\androidTest\debug;D:\Repositories\android-util\util\build\intermediates\compile_r_class_jar\debug\R.jar;D:\Repositories\android-util\util\build\tmp\kotlin-classes\debug;D:\Repositories\android-util\util\build\generated\res\resValues\debug;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.4.10\ea29e063d2bbe695be13e9d044dcfb0c7add398e\kotlin-stdlib-1.4.10.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib-common\1.4.10\6229be3465805c99db1142ad75e6c6ddeac0b04c\kotlin-stdlib-common-1.4.10.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\androidx.lifecycle\lifecycle-common\2.0.0\e070ffae07452331bc5684734fce6831d531785c\lifecycle-common-2.0.0.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\androidx.arch.core\core-common\2.0.0\bb21b9a11761451b51624ac428d1f1bb5deeac38\core-common-2.0.0.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\androidx.collection\collection\1.0.0\42858b26cafdaa69b6149f45dfc2894007bc2c7a\collection-1.0.0.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\androidx.annotation\annotation\1.1.0\e3a6fb2f40e3a3842e6b7472628ba4ce416ea4c8\annotation-1.1.0.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\477c30dd9432ccabb67d27175ca0c3dd\jetified-core-ktx-1.3.2\jars\classes.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\477c30dd9432ccabb67d27175ca0c3dd\jetified-core-ktx-1.3.2\AndroidManifest.xml;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\30d5e2a30ce73cde3a4ea55aa649a92b\core-1.3.2\jars\classes.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\30d5e2a30ce73cde3a4ea55aa649a92b\core-1.3.2\res;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\30d5e2a30ce73cde3a4ea55aa649a92b\core-1.3.2\AndroidManifest.xml;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\994e0568a00708a2974911000d1d547b\lifecycle-runtime-2.0.0\jars\classes.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\994e0568a00708a2974911000d1d547b\lifecycle-runtime-2.0.0\AndroidManifest.xml;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\868201dca875931c6c17d79f95b6d7ea\versionedparcelable-1.1.0\jars\classes.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\868201dca875931c6c17d79f95b6d7ea\versionedparcelable-1.1.0\AndroidManifest.xml;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-test\1.4.10\c57ab8d7f12f4ffcd45c63f837228861c9f2cd9a\kotlin-test-1.4.10.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\junit\junit\4.13\e49ccba652b735c93bd6e6f59760d8254cf597dd\junit-4.13.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-core\1.3\42a25dc3219429f0e5d060061f71acb49bf010a0\hamcrest-core-1.3.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.robolectric\robolectric\4.4\418c5bfae392fdbf71cd463a42a3e8c3b839a924\robolectric-4.4.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.robolectric\shadows-framework\4.4\90028766e71353ad6f57d7bcb56ac0d861da18c3\shadows-framework-4.4.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\io.mockk\mockk\1.10.2\6695fee82fec0186d107dd4d01fe36cc4d886b13\mockk-1.10.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-test-common\1.4.10\505c602601309cd1694a369aacb6df4dcf5c9a4\kotlin-test-common-1.4.10.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\io.mockk\mockk-common\1.10.2\2c9fb093ab4d34c25d616e12854711807d067d0d\mockk-common-1.10.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\io.mockk\mockk-dsl-jvm\1.10.2\814462244f7d36d3da63b4ff1f37ef07aa640685\mockk-dsl-jvm-1.10.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\io.mockk\mockk-dsl\1.10.2\ae8d837b4b40ef4752fb09f4b9aa3ca021686210\mockk-dsl-1.10.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.robolectric\junit\4.4\fbcda51d8e6f3a3897ae5cedc7aa481815745290\junit-4.4.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.robolectric\resources\4.4\a2ee1324bcb62724e6cbfa655bdb5683948a554c\resources-4.4.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.robolectric\sandbox\4.4\3cedd73c5aedaf79fb9a593552816c9fb3282f2\sandbox-4.4.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.robolectric\utils-reflector\4.4\44c40ac0d2ef1e7c8b0f6c4e224ef26d356170f1\utils-reflector-4.4.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.robolectric\plugins-maven-dependency-resolver\4.4\9241a3c4bd01627447c76d9b67614808c78ffdd9\plugins-maven-dependency-resolver-4.4.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.robolectric\utils\4.4\c54b2638d64e7bd4e1e45c4fe8038305402bd711\utils-4.4.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.robolectric\pluginapi\4.4\1ee94260f8c51620a35eac33fc1efc01350c751f\pluginapi-4.4.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.robolectric\shadowapi\4.4\529649474b53cf8f6f4a483044ade43aebed8a4c\shadowapi-4.4.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.robolectric\annotations\4.4\70fc5b1699467dfd7de606fc6c02ff9fc1816d9f\annotations-4.4.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\javax.inject\javax.inject\1\6975da39a7040257bd51d21a231b76c915872d38\javax.inject-1.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\javax.annotation\javax.annotation-api\1.3.2\934c04d3cfef185a8008e7bf34331b79730a9d43\javax.annotation-api-1.3.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\com.google.guava\guava\27.0.1-jre\bd41a290787b5301e63929676d792c507bbc00ae\guava-27.0.1-jre.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\com.google.guava\failureaccess\1.0.1\1dcf1de382a0bf95a3d8b0849546c88bac1292c9\failureaccess-1.0.1.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\com.google.guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\b421526c5f297295adef1c886e5246c39d4ac629\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\com.google.code.findbugs\jsr305\3.0.2\25ea2e8b0c338a877313bd4672d3fe056ea78f0d\jsr305-3.0.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.checkerframework\checker-qual\2.5.2\cea74543d5904a30861a61b4643a5f2bb372efc4\checker-qual-2.5.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\com.google.errorprone\error_prone_annotations\2.2.0\88e3c593e9b3586e1c6177f89267da6fc6986f0c\error_prone_annotations-2.2.0.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\com.google.j2objc\j2objc-annotations\1.1\ed28ded51a8b1c6b112568def5f4b455e6809019\j2objc-annotations-1.1.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.codehaus.mojo\animal-sniffer-annotations\1.17\f97ce6decaea32b36101e37979f8b647f00681fb\animal-sniffer-annotations-1.17.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.ow2.asm\asm-commons\7.2\ca2954e8d92a05bacc28ff465b25c70e0f512497\asm-commons-7.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.ow2.asm\asm-util\7.2\a3ae34e57fa8a4040e28247291d0cc3d6b8c7bcf\asm-util-7.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.ow2.asm\asm-analysis\7.2\b6e6abe057f23630113f4167c34bda7086691258\asm-analysis-7.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.ow2.asm\asm-tree\7.2\3a23cc36edaf8fc5a89cb100182758ccb5991487\asm-tree-7.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.ow2.asm\asm\7.2\fa637eb67eb7628c915d73762b681ae7ff0b9731\asm-7.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\com.almworks.sqlite4java\sqlite4java\0.282\745a7e2f35fdbe6336922e0d492c979dbbfa74fb\sqlite4java-0.282.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\com.ibm.icu\icu4j\53.1\786d9055d4ca8c1aab4a7d4ac8283f973fd7e41f\icu4j-53.1.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\com.google.auto.value\auto-value-annotations\1.6.2\ed193d86e0af90cc2342aedbe73c5d86b03fa09b\auto-value-annotations-1.6.2.jar;C:\Users\Alix\.gradle\caches\modules-2\files-2.1\org.bouncycastle\bcprov-jdk15on\1.65\320b989112f00a63a3bcfa5a98f31a4f865a20fa\bcprov-jdk15on-1.65.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\9f88c5bf9463783a3d9716f875c82c97\jetified-junit-1.1.2\jars\classes.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\9f88c5bf9463783a3d9716f875c82c97\jetified-junit-1.1.2\AndroidManifest.xml;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\d661f3cba2900724f24f5e7eb2a23e9e\jetified-core-1.3.0\jars\classes.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\d661f3cba2900724f24f5e7eb2a23e9e\jetified-core-1.3.0\AndroidManifest.xml;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\41a6ecd7e45662dfdfa44e09dfa56476\monitor-1.3.0\jars\classes.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\41a6ecd7e45662dfdfa44e09dfa56476\monitor-1.3.0\AndroidManifest.xml;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\3d74859a47ca0a79b56dd3c1baca6078\jetified-testutil-0.7.0\jars\classes.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\3d74859a47ca0a79b56dd3c1baca6078\jetified-testutil-0.7.0\AndroidManifest.xml;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\ac62b608bf74c29baedefa85a525daf6\jetified-kotlin-reflect-1.3.61.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\88a295fcb169bd1372ca0ebff8353c59\jetified-mockk-agent-jvm-1.10.2.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\8bc32d1c9a05dc89067da1bb96424ec9\jetified-mockk-agent-common-1.10.2.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\43cf5a6551e9201e1f594ee26acc8bed\jetified-mockk-agent-api-1.10.2.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\6d585d211dffc23f2fba39b2fca9f8e4\jetified-objenesis-3.1.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\f40810de993d02612afcc2326b3adb3a\jetified-byte-buddy-1.10.14.jar;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\12007de34cacaacd123ca8279c80c930\jetified-byte-buddy-agent-1.10.14.jar;D:\Repositories\android-util\util\build\intermediates\java_res\debugUnitTest\out;D:\Repositories\android-util\util\build\intermediates\java_res\debug\out;C:\Users\Alix\.gradle\caches\transforms-2\files-2.1\95fda4a68c96b43a370a32595b954319\android.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 com.assaabloy.stg.android.util.crypto.AesKeyProviderTest
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access using Lookup on io.mockk.proxy.jvm.ClassLoadingStrategyChooser (file:/C:/Users/Alix/.gradle/caches/transforms-2/files-2.1/88a295fcb169bd1372ca0ebff8353c59/jetified-mockk-agent-jvm-1.10.2.jar) to interface javax.crypto.SecretKey
WARNING: Please consider reporting this to the maintainers of io.mockk.proxy.jvm.ClassLoadingStrategyChooser
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

java.lang.NoClassDefFoundError: io/mockk/proxy/jvm/advice/jvm/JvmMockKProxyInterceptor

	at java.base/javax.crypto.SecretKey$Subclass0.equals(Unknown Source)
	at kotlin.jvm.internal.Intrinsics.areEqual(Intrinsics.java:167)
	at kotlin.test.Asserter$DefaultImpls.assertEquals(Assertions.kt:245)
	at kotlin.test.DefaultAsserter.assertEquals(DefaultAsserter.kt:11)
	at kotlin.test.AssertionsKt__AssertionsKt.assertEquals(Assertions.kt:57)
	at kotlin.test.AssertionsKt.assertEquals(Unknown Source)
	at kotlin.test.AssertionsKt__AssertionsKt.assertEquals$default(Assertions.kt:56)
	at kotlin.test.AssertionsKt.assertEquals$default(Unknown Source)
	at com.mycompany.Foo...
	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:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:575)
	at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:263)
	at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)


com.assaabloy.stg.android.util.crypto.EncryptionException: Could not initialize secret key.

	at com.mycompany.Foo...
	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:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:575)
	at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:263)
	at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.security.NoSuchProviderException: JCE cannot authenticate the provider AndroidKeyStore
	at java.base/javax.crypto.JceSecurity.getInstance(JceSecurity.java:132)
	at java.base/javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:287)
	at 
at com.mycompany.Foo...
	... 18 more
Caused by: java.lang.NullPointerException
	at java.base/javax.crypto.ProviderVerifier.verify(ProviderVerifier.java:122)
	at java.base/javax.crypto.JceSecurity.verifyProvider(JceSecurity.java:191)
	at java.base/javax.crypto.JceSecurity.getVerificationResult(JceSecurity.java:217)
	at java.base/javax.crypto.JceSecurity.getInstance(JceSecurity.java:129)
	... 20 more

Process finished with exit code -1

Stack trace

// -----------------------[ YOUR STACK STARTS HERE ] -----------------------
io.mockk.MockKException: Class cast exception. Probably type information was erased.
In this case use `hint` before call to specify exact return type of a method. 

	at io.mockk.impl.InternalPlatform.prettifyRecordingException(InternalPlatform.kt:83)
	at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:50)
	at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:25)
	at eu.example.schedule.kafka.KafkaAdminImplTest.mockkVoidReturnFails(KafkaAdminImplTest.kt:301)
	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.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	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.ClassCastException: kotlin.Unit cannot be cast to java.lang.Void
	at eu.example.schedule.kafka.KafkaAdminImplTest$mockkVoidReturnFails$1.invoke(KafkaAdminImplTest.kt:87)
	at eu.example.schedule.kafka.KafkaAdminImplTest$mockkVoidReturnFails$1.invoke(KafkaAdminImplTest.kt:24)
	at io.mockk.impl.eval.RecordedBlockEvaluator$record$block$1.invoke(RecordedBlockEvaluator.kt:22)
	at io.mockk.impl.recording.JvmAutoHinter.autoHint(JvmAutoHinter.kt:23)
	at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:31)
	... 25 more
// -----------------------[ YOUR STACK TRACE ENDS HERE ] -----------------------

Minimal reproducible code (the gist of this issue)

// -----------------------[ GRADLE DEFINITIONS ] -----------------------
Root:

buildscript {
  dependencies {
        classpath("com.android.tools.build:gradle:4.1.0")
}
}

Module:
... 

plugins {
    id("com.android.library")
    id("org.jetbrains.kotlin.android")
}

android {
    compileSdkVersion(30)
    defaultConfig {
        minSdkVersion(21)
        targetSdkVersion(30)
    }
    lintOptions {
        isAbortOnError = false
    }

    testOptions {
        unitTests.isReturnDefaultValues = true
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    buildTypes {
        getByName("release") {
            isDebuggable = false
        }
        getByName("debug") {
            isDebuggable = true
        }
    }
}

dependencies {
    testImplementation("io.mockk:mockk:1.10.2")
    testImplementation("junit:junit:4.13")
    testImplementation("org.jetbrains.kotlin:kotlin-test:1.4.10")
    testImplementation("org.robolectric:robolectric:4.4")
}
// -----------------------[ YOUR CODE STARTS HERE ] -----------------------
package io.mockk.gh

import android.os.Build
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.mockk.mockkClass
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.annotation.Config
import java.security.KeyStore
import javax.crypto.SecretKey
import kotlin.test.assertNotNull
import kotlin.test.assertNull

@Config(sdk = [Build.VERSION_CODES.M], manifest = Config.NONE)
@RunWith(AndroidJUnit4::class)
class IssueProblemTest {

    @Test
    fun test() {
        keyStore = KeyStore.getInstance("AndroidKeyStore")
       keyStore.load(null)
        val secretKey = mockkClass(SecretKey::class)
        assertNotNull(secretKey.toString())
    }

}
// -----------------------[ YOUR CODE ENDS HERE ] -----------------------
@Raibaz
Copy link
Collaborator

Raibaz commented Nov 18, 2020

I have been trying to reproduce this, but I was able to successfully execute the code snippet you provided.

Out of curiosity: why are you using mockClass(SecretKey::class) rather than mockk<SecretKey>()?

@Raibaz Raibaz added the android label Nov 26, 2020
@stale
Copy link

stale bot commented Jan 31, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. If you are sure that this issue is important and should not be marked as stale just ask to put an important label.

@stale stale bot added the stale label Jan 31, 2021
@stale stale bot closed this as completed Feb 9, 2021
@agebhar1
Copy link
Contributor

agebhar1 commented Jul 6, 2021

Hello @Raibaz,

upgrade from 1.9.2 to latest 1.12.0 fails with the same error on all tests. You can find these here https://github.com/agebhar1/prototype-xslt-data-url/runs/2998173263?check_suite_focus=true

@angryziber
Copy link

I get the same error when trying to mock a class from Java module, e.g. jdk.httpserver

mockk<HttpExchange>(relaxed = true)

It seems the generated code that is put inside of the class in a module package cannot get access to mockk itself...

@luispollo
Copy link

Any updates on this?

@pk97
Copy link

pk97 commented Mar 16, 2023

I am facing the same issue. Any updates?

@shantiswarup
Copy link

any solution for this ?

@pelias-bc
Copy link

I'm also experiencing this issue

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

No branches or pull requests

8 participants