Bug: StackOverflowError related to spyk'ing objects that call super method
See original GitHub issuePrerequisites
- I am running the latest version
- I checked the documentation and found no answer
- I checked to make sure that this issue has not already been filed*
*a similar, but possibly not quite exact error is here, people point to the JVM being the culprit which does not appear to be the issue here hence new issue
Expected Behavior
I am trying to spyk a class which calls a method in its super class. The class should then be mockable/verifiable.
Current Behavior
The tests fail to run with a java.lang.StackOverflowError.
Steps to Reproduce
Please provide detailed steps for reproducing the issue.
- download repro project attached.
- run HomePresenterTest
- StackOverflowError
Context
- MockK version: 1.12.0
- OS: MacOS 11.3.1
- Kotlin version: 1.5.21, 1.5.30
- JDK version: 11.0.12 (x86_64) “Eclipse Temurin” - “Eclipse Temurin 11”. However also reproducible on following versions: 16.0.2 (x86_64) “Homebrew” - “OpenJDK 16.0.2” 11.0.10 (x86_64) “UNDEFINED” - “OpenJDK 11.0.10”
- JUnit version: 4.13.2
- Type of test: unit test
- Robolectric version: 4.5.1
Stack trace
java.lang.StackOverflowError
at kotlin.reflect.jvm.internal.impl.types.AbstractClassTypeConstructor.equals(AbstractClassTypeConstructor.java:76)
at kotlin.jvm.internal.Intrinsics.areEqual(Intrinsics.java:167)
at kotlin.reflect.jvm.internal.impl.types.checker.ClassicTypeSystemContext$DefaultImpls.isEqualTypeConstructors(ClassicTypeSystemContext.kt:216)
at kotlin.reflect.jvm.internal.impl.types.checker.SimpleClassicTypeSystemContext.isEqualTypeConstructors(NewKotlinTypeChecker.kt:33)
at kotlin.reflect.jvm.internal.impl.types.AbstractStrictEqualityTypeChecker.strictEqualSimpleTypes(AbstractStrictEqualityTypeChecker.kt:44)
at kotlin.reflect.jvm.internal.impl.types.AbstractStrictEqualityTypeChecker.strictEqualTypesInternal(AbstractStrictEqualityTypeChecker.kt:29)
at kotlin.reflect.jvm.internal.impl.types.AbstractStrictEqualityTypeChecker.strictEqualTypes(AbstractStrictEqualityTypeChecker.kt:13)
at kotlin.reflect.jvm.internal.impl.types.checker.StrictEqualityTypeChecker.strictEqualTypes(NewKotlinTypeChecker.kt:45)
at kotlin.reflect.jvm.internal.impl.types.KotlinType.equals(KotlinType.kt:117)
at kotlin.jvm.internal.Intrinsics.areEqual(Intrinsics.java:167)
at kotlin.reflect.jvm.internal.impl.renderer.DescriptorRendererImpl.renderSimpleType(DescriptorRendererImpl.kt:161)
at kotlin.reflect.jvm.internal.impl.renderer.DescriptorRendererImpl.renderNormalizedTypeAsIs(DescriptorRendererImpl.kt:156)
at kotlin.reflect.jvm.internal.impl.renderer.DescriptorRendererImpl.renderNormalizedType(DescriptorRendererImpl.kt:134)
at kotlin.reflect.jvm.internal.impl.renderer.DescriptorRendererImpl.renderType(DescriptorRendererImpl.kt:116)
at kotlin.reflect.jvm.internal.ReflectionObjectRenderer.renderType(ReflectionObjectRenderer.kt:122)
at kotlin.reflect.jvm.internal.KTypeImpl.toString(KTypeImpl.kt:125)
at io.mockk.impl.instantiation.JvmMockFactoryHelper.toDescription$mockk(JvmMockFactoryHelper.kt:129)
at io.mockk.impl.instantiation.JvmMockFactoryHelper$mockHandler$1.invocation(JvmMockFactoryHelper.kt:25)
at io.mockk.proxy.jvm.advice.Interceptor.call(Interceptor.kt:21)
at com.example.mockkstackoverflowexceptiondemo.base.HomePresenter.onViewAttached(Base.kt:40)
at com.example.mockkstackoverflowexceptiondemo.base.HomePresenter.onViewAttached(Base.kt:33)
... snip ...
Minimal reproducible code (the gist of this issue)
Project code
package com.example.mockkstackoverflowexceptiondemo.base
import androidx.annotation.CallSuper
abstract class MvpPresenter<V : MvpView> {
var view: V? = null
fun attachView(view: V) {
this.view = view
onViewAttached(view)
}
fun detachView() { view = null }
@CallSuper
open fun onViewAttached(view: V) {
// not reproducible if abstract.
}
}
interface MvpView
class HomePresenter : MvpPresenter<HomeView>() {
override fun onViewAttached(view: HomeView) {
super.onViewAttached(view)
}
}
interface HomeView : MvpView
Test code
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [28])
class HomePresenterTest {
@Test fun someTest() {
val presenter = spyk(HomePresenter())
val view = mockk<HomeView>(relaxed = true)
presenter.attachView(view)
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7
Top Results From Across the Web
java - StackOverflowError exception when calling method
I am getting StackOverflowError overflow exception when calling a method that only contains print statement. Below is the code public class Dog ...
Read more >The StackOverflowError in Java
When a method is called, a new stack frame gets created on the call stack. This stack frame holds parameters of the invoked...
Read more >Bug listing with status UNCONFIRMED as at 2022/12/19 13 ...
Bug :128538 - "sys-apps/coreutils: /bin/hostname should be installed from coreutils not sys-apps/net-tools" status:UNCONFIRMED resolution: severity:enhancement ...
Read more >The only 3 steps you need to mock an API call in Jest
You can incrementally add some of the concepts below to super-charge your mocks: Check out the other mock function methods listed in the...
Read more >Spring Boot Reference Documentation
If you are starting out with Spring, try one of the guides. Ask a question. We monitor stackoverflow.com for questions tagged with spring-boot...
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
This is still an issue and should not be closed without investigation. I’ve attached a sample above to repro.
On Sat, 16 Apr 2022, 7:58 pm stale[bot], @.***> wrote:
I’m having the same issue, no Roboeletric involved for me though, just a simple JUnit4 test