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.

java.lang.InstantiationError when upgrading to Kotlin 1.7

See original GitHub issue

Java 17 + Kotlin 1.7 + Mockk 1.12.4/Spring Mockk 3.1.1

java.lang.InstantiationError: com.example.demo.UpdateAccountResult
    at jdk.internal.reflect.GeneratedSerializationConstructorAccessor18.newInstance(Unknown Source)
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
    at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:48)

It occurred whens using coEvery{} to do some stub, which returns a UpdateAccountResult.Success().

Here UpdateAccountResult is a sealed class, it has some detailed result subclass/sub data classes.

And UpdateAccountResult extends from a base abstract class like this.

abstract class ApiBaseResult {
    @field:JsonProperty("SC")
    val statusCode: String? = null

    @field:JsonProperty("EC")
    val errorCode: String? = null

    @field:JsonProperty("EM")
    val errorMessage: String? = null
}

These codes are working well with Kotlin 1.6.21.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:61
  • Comments:55 (12 by maintainers)

github_iconTop GitHub Comments

26reactions
hantsycommented, Jun 27, 2022

Any update for this issue, is there any workaround?

15reactions
Raibazcommented, Jul 26, 2022

I’m currently having issues publishing to oss.sonatype.org: https://issues.sonatype.org/browse/OSSRH-83030

As soon as this is resolved, I’ll publish a new release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java.lang.InstantiationError when mocking method with ...
I am using Kotlin 1.7.10 and Mockk 1.12.4 and I have a factory method in the following spring bean class:
Read more >
I m trying to upgrade Kotlin to 1 7 0 and I m no longer able
I'm trying to upgrade Kotlin to 1.7.0 and I'm no longer able to get my buildSrc project to configure. It's breaking on applying...
Read more >
mockk-io/Lobby - Gitter
Hi , today I upgrade my project to Kotlin 1.7, but some mockk failed the tests. java.lang.InstantiationError: com.example.demo.
Read more >
error after upgrading to 8.0.5 - Prime Community Forum
Code: Select all. Caused by: java.lang.InstantiationError: org.primefaces.util.Lazy at deployment.sigp-apps.war//org.primefaces.csp.
Read more >
Kotlin 1.7.20 Released - The JetBrains Blog
How to install Kotlin 1.7.20. If you already use IntelliJ IDEA 2021.3, 2022.1, or 2022.2, the IDE will suggest updating Kotlin to 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