java.lang.InstantiationError when upgrading to Kotlin 1.7
See original GitHub issueJava 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:
- Created a year ago
- Reactions:61
- Comments:55 (12 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any update for this issue, is there any workaround?
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.