-1

Same code using with Android studio Dolphin, it works fine, but after update the Android Studio Electric Eel | 2022.1.1 Patch 1, it starts to fail.

    @Test
   
    fun test_connection() {
        val url = URL("http://www.google.com")
        try {
            val urlSpy = spyk(url) //<=== throw exception now
            every { urlSpy.openConnection() } returns null
        } catch(e: Throwable) {
            System.out.println("+++ !!! exp: $e")
            e.printStackTrace()
        }
    }

It uses Java 11. It is using mockkVersion : "1.12.0" (but changed to 1.13.4 with AndroidStudio EEL)

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:7.10.0" (tried changed to 7.20.0 with AndroidStudio EEL)

classpath "com.android.tools.build:gradle:7.2.1" (tried 7.3.1 with Android studio EEl)

https://services.gradle.org/distributions/gradle-7.4-bin.zip (tried 7.5 with Android studio EEl)

+++ !!! exp: java.lang.IllegalAccessException: class io.mockk.impl.InternalPlatform cannot access a member of class java.net.URL (in module java.base) with modifiers "private"
java.lang.IllegalAccessException: class io.mockk.impl.InternalPlatform cannot access a member of class java.net.URL (in module java.base) with modifiers "private"
    at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:392)
    at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674)
    at java.base/java.lang.reflect.Field.checkAccess(Field.java:1102)
    at java.base/java.lang.reflect.Field.get(Field.java:423)
    at io.mockk.impl.InternalPlatform.copyFields$copy(InternalPlatform.kt:114)
    at io.mockk.impl.InternalPlatform.copyFields(InternalPlatform.kt:121)
    at io.mockk.impl.instantiation.AbstractMockFactory.spyk(AbstractMockFactory.kt:107)
    at com.test.HandlerTestK.test_connection(HandlerTestK.kt:1077)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    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.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
    at org.robolectric.RobolectricTestRunner$HelperTestRunner$1.evaluate(RobolectricTestRunner.java:591)
    at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:274)
    at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:88)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
lannyf
  • 9,865
  • 12
  • 70
  • 152

1 Answers1

0

Looks like there is some problem using java 17 with mockk. Dont realize the AndroidStudio EE is default to using java 17 instead of carry over the project setting with what has been set on Androidstuido Dolphin (it was set using java 11).

enter image description here

lannyf
  • 9,865
  • 12
  • 70
  • 152