question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StackOverflowError using Kotlin 1.7.20

See original GitHub issue

Context

  • MockK version: 1.12.8
  • ByteBuddy version: 1.12.13
  • OS: MacOS
  • Kotlin version: 1.7.20
  • JDK version: 18.0.2
  • JUnit version: 5.9.0
  • Type of test: unit test (no containers)

Failure Logs

Cannot invoke "io.vertx.ext.mongo.MongoClient.replaceDocumentsWithOptions(String, io.vertx.core.json.JsonObject, io.vertx.core.json.JsonObject, io.vertx.ext.mongo.UpdateOptions)" because the return value of "kn.tqt.db.store.base.AbstractRepository.getDbClient()" is null
java.lang.NullPointerException: Cannot invoke "io.vertx.ext.mongo.MongoClient.replaceDocumentsWithOptions(String, io.vertx.core.json.JsonObject, io.vertx.core.json.JsonObject, io.vertx.ext.mongo.UpdateOptions)" because the return value of "kn.tqt.db.store.base.AbstractRepository.getDbClient()" is null
	at kn.tqt.db.store.base.AbstractRepository.upsert$suspendImpl(AbstractRepository.kt:47)
	at kn.tqt.db.store.base.AbstractRepository.upsert(AbstractRepository.kt)

Stack trace

java.lang.StackOverflowError: null
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.of(TypeDescription.java:2008)
	at net.bytebuddy.description.type.TypeList$Generic$ForDetachedTypes.attachVariables(TypeList.java:561)
	at net.bytebuddy.description.method.MethodDescription$Latent.getTypeVariables(MethodDescription.java:1455)
	at net.bytebuddy.description.TypeVariableSource$AbstractBase.findVariable(TypeVariableSource.java:157)
	at net.bytebuddy.description.TypeVariableSource$AbstractBase.findExpectedVariable(TypeVariableSource.java:172)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onTypeVariable(TypeDescription.java:2035)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onTypeVariable(TypeDescription.java:1946)
	at net.bytebuddy.description.type.TypeDescription$Generic$OfTypeVariable$Symbolic.accept(TypeDescription.java:5856)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor.onParameterizedType(TypeDescription.java:1881)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onParameterizedType(TypeDescription.java:1946)
	at net.bytebuddy.description.type.TypeDescription$Generic$OfParameterizedType.accept(TypeDescription.java:5059)
	at net.bytebuddy.description.method.ParameterDescription$Latent.getType(ParameterDescription.java:805)
	at net.bytebuddy.description.method.ParameterList$AbstractBase.asTypeList(ParameterList.java:107)
	at net.bytebuddy.description.method.MethodDescription$AbstractBase.toString(MethodDescription.java:1006)
	at java.base/java.lang.String.valueOf(String.java:4213)
	at java.base/java.lang.StringBuilder.append(StringBuilder.java:173)
	at net.bytebuddy.description.TypeVariableSource$AbstractBase.findExpectedVariable(TypeVariableSource.java:174)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onTypeVariable(TypeDescription.java:2035)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onTypeVariable(TypeDescription.java:1946)
	at net.bytebuddy.description.type.TypeDescription$Generic$OfTypeVariable$Symbolic.accept(TypeDescription.java:5856)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor.onParameterizedType(TypeDescription.java:1881)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onParameterizedType(TypeDescription.java:1946)
	at net.bytebuddy.description.type.TypeDescription$Generic$OfParameterizedType.accept(TypeDescription.java:5059)
	at net.bytebuddy.description.method.ParameterDescription$Latent.getType(ParameterDescription.java:805)
	at net.bytebuddy.description.method.ParameterList$AbstractBase.asTypeList(ParameterList.java:107)
	at net.bytebuddy.description.method.MethodDescription$AbstractBase.toString(MethodDescription.java:1006)
	at java.base/java.lang.String.valueOf(String.java:4213)
	at java.base/java.lang.StringBuilder.append(StringBuilder.java:173)
...

Minimal reproducible code (the gist of this issue)

mockk<TotalBidSummaryRepository>().apply {
      coEvery { upsert(any()) } coAnswers {
        val summary = firstArg<TotalBidSummary>()
        state[summary.rfqNum] = summary
        true
      }
      coEvery { findNullable(any()) } coAnswers {
        state[firstArg()]?.deepCopy()
      }
      coEvery { find(any()) } coAnswers {
        state[firstArg()]!!.deepCopy()
      }
    }

class TotalBidSummaryRepository(dbClient: MongoClient) :
  AbstractRepository<TotalBidSummary>(dbClient, "TotalBidSummary", TotalBidSummary::class)

abstract class AbstractRepository<T : Any>(
  dbClient: MongoClient,
  collectionName: String,
  clazz: KClass<T>
) : AbstractReadOnlyRepository<T>(dbClient, collectionName, clazz) {

P.S. maybe byte-buddy issue?

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:7
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
stuebingerbcommented, Oct 5, 2022

Same here with a similar setup. Works with Kotlin 1.7.10 but fails with 1.7.20, if this helps.

1reaction
ferinagycommented, Oct 13, 2022

I ran into similar issue. My minimal repro case is:

import io.mockk.every
import io.mockk.mockk
import org.junit.Test

class MockkTest {

    @Test
    fun test() {
        mockk<TestClass<Unit>> {
            every { state } returns 0
        }
    }
}

abstract class TestClass<T> {
    val state: Int = TODO()
    open suspend fun doCreate(): Int = TODO()
}

It also works with kotlin 1.7.10, but fails with 1.7.20. The error we see when running the test as a part of our Android project is:

Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock
io.mockk.MockKException: Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock
	at app//io.mockk.impl.recording.states.StubbingState.checkMissingCalls(StubbingState.kt:14)
	at app//io.mockk.impl.recording.states.StubbingState.recordingDone(StubbingState.kt:8)
	at app//io.mockk.impl.recording.CommonCallRecorder.done(CommonCallRecorder.kt:47)
	at app//io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:64)
	at app//io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:30)
	at app//io.mockk.MockKDsl.internalEvery(API.kt:93)
	at app//io.mockk.MockKKt.every(MockK.kt:98)
	at app//at.beeone.george.MockkTest.test(MockkTest.kt:13)
	at java.base@11.0.16.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base@11.0.16.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base@11.0.16.1/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base@11.0.16.1/java.lang.reflect.Method.invoke(Method.java:566)
	at app//org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at app//org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at app//org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at app//org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at app//org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at app//org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at app//org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at app//org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at app//org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at app//org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at app//org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at app//org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at app//org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at app//org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at app//org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at app//org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.runTestClass(JUnitTestClassExecutor.java:110)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:58)
	at org.gradle.api.internal.tasks.testing.junit.JUnitTestClassExecutor.execute(JUnitTestClassExecutor.java:38)
	at org.gradle.api.internal.tasks.testing.junit.AbstractJUnitTestClassProcessor.processTestClass(AbstractJUnitTestClassProcessor.java:62)
	at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.processTestClass(SuiteTestClassProcessor.java:51)
	at java.base@11.0.16.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base@11.0.16.1/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base@11.0.16.1/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base@11.0.16.1/java.lang.reflect.Method.invoke(Method.java:566)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
	at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
	at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
	at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
	at com.sun.proxy.$Proxy5.processTestClass(Unknown Source)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker$2.run(TestWorker.java:176)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
	at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
	at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
	at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
	at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
	at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)

After extracting the repro case to pure jvm console app, I also see the stackoverflow error before:

WARNING: Failed to transform class TestClass
java.lang.StackOverflowError
	at net.bytebuddy.description.TypeVariableSource$AbstractBase.findExpectedVariable(TypeVariableSource.java:171)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onTypeVariable(TypeDescription.java:2033)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onTypeVariable(TypeDescription.java:1944)
	at net.bytebuddy.description.type.TypeDescription$Generic$OfTypeVariable$Symbolic.accept(TypeDescription.java:5854)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor.onParameterizedType(TypeDescription.java:1879)
	at net.bytebuddy.description.type.TypeDescription$Generic$Visitor$Substitutor$ForAttachment.onParameterizedType(TypeDescription.java:1944)
	at net.bytebuddy.description.type.TypeDescription$Generic$OfParameterizedType.accept(TypeDescription.java:5057)
	at net.bytebuddy.description.method.ParameterDescription$Latent.getType(ParameterDescription.java:805)
	at net.bytebuddy.description.method.ParameterList$AbstractBase.asTypeList(ParameterList.java:107)
	at net.bytebuddy.description.method.MethodDescription$AbstractBase.toString(MethodDescription.java:1006)
	at java.base/java.lang.String.valueOf(String.java:2951)
	at java.base/java.lang.StringBuilder.append(StringBuilder.java:173)
	at net.bytebuddy.description.TypeVariableSource$AbstractBase.findExpectedVariable(TypeVariableSource.java:173)
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Upgrading Kotlin Gradle plugins to version 1.7.20 causes ...
I have Kotlin/Spring Boot project that is using the following Kotlin-Gradle plugins: ... Facing the same issue with Kotlin 1.7.20.
Read more >
What's new in Kotlin 1.7.0
The new Kotlin K2 compiler is in Alpha now, and it offers serious ... itself recursively 100,000 times, no StackOverflowError is thrown:.
Read more >
What's new in Kotlin 1.7.20
The Kotlin 1.7.20 release is out! Here are some highlights from this release: The new Kotlin K2 compiler supports all-open , SAM with...
Read more >
FAQ | Kotlin
Is Kotlin compatible with the Java programming language? ... StackOverflow and more actively on the Kotlin Slack (with close to 30000 ...
Read more >
Anybody else getting a lot of build failures if you dependab
plugins { kotlin("jvm") version "1.7.20" kotlin("plugin.serialization") ... 27 > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin-api:1.7.20.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found