mockk: InliningClassTransformer - Failed to transform class with a java.lang.ArrayIndexOutOfBoundsException, followed by NPE
Prerequisites
Please answer the following questions for yourself before submitting an issue.
- 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
Expected Behavior
I am testing one class that receives multiple constructor injected guice dependencies, most of them have their own constructor injected dependencies. In my test @Before function, I define the mock behavior by using things like every { dependency.method(any(),...) } returns true
. For example, one of the dependency is a guice singleton with a constructor injected dependency:
@Singleton
class ProcessTracker @Inject constructor(private val anotherController: AnotherController) {
fun startJob(msg: SomeMessage) : Boolean {
val fetchedJobStatus = anotherController.fetchJob(msg.id, msg.name)
...
}
}
In my test:
class MyTest {
@MockK private lateinit var otherDependency1: OtherDependency1
@MockK private lateinit var otherDependency2: OtherDependency2
@MockK private lateinit var processTracker: ProcessTracker
@MockK private lateinit var classUnderTest: ClassUnderTest
...
@Before
fun setUp() {
MockKAnnotations.init(this, relaxUnitFun = true)
every { otherDependency1.someMethod1(any(), any()) } just Runs
every { otherDependency1.someMethod2(any(), any(), any()) } returns 3
every { processTracker.startJob(any()) } returns true
...
classUnderTest = spyk(ClassUnderTest(otherDependency1, otherDependency2, processTracker, ...), recordPrivateCalls=true)
}
@After
fun tearDown() {
unmockkAll()
}
@Test
fun myFirstTest() {
val msg = buildMessage()
classUnderTest.methodToTest(msg)
verify {...}
verify {...}
}
}
I expect the mocked behavior of ProcessTracker.startJob
be mocked and just return true in the tests.
Current Behavior
I’m getting the following errors:
io.mockk.proxy.jvm.transformation.InliningClassTransformer - Failed to transform class com/mycompany/myproject/ClassUnderTest
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at net.bytebuddy.asm.Advice$StackMapFrameHandler$Default$TranslationMode$1.copy(Advice.java:1301)
at net.bytebuddy.asm.Advice$StackMapFrameHandler$Default.translateFrame(Advice.java:1192)
at net.bytebuddy.asm.Advice$StackMapFrameHandler$Default.translateFrame(Advice.java:1141)
...
followed by another error:
[main] WARN io.mockk.proxy.jvm.transformation.InliningClassTransformer - Failed to transform class com/mycompany/myproject/.../ProcessTracker
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at net.bytebuddy.asm.Advice$StackMapFrameHandler$Default$TranslationMode$1.copy(Advice.java:1301)
at net.bytebuddy.asm.Advice$StackMapFrameHandler$Default.translateFrame(Advice.java:1192)
at net.bytebuddy.asm.Advice$StackMapFrameHandler$Default.translateFrame(Advice.java:1141)
at net.bytebuddy.asm.Advice$AdviceVisitor.visitFrame(Advice.java:6590)
...
and finally:
java.lang.NullPointerException
at com.mycompany.<>.<>.ProcessTracker.startJob(ProcessTracker.kt: 23)
...
Also I should note that sometimes I make some small changes that I don’t think is substantial, and then the test would pass. Then I git commit
that, close the project, open it again and run the test, it would fail with the same exceptions again.
One thing to note is that ProcessTracker
is not the only guice injected singleton with a constructor injected dependency. Some of the other dependencies are also the same way. However, I’m getting the exceptions at this class only.
Failure Information (for bugs)
Please see above description.
Steps to Reproduce
I’ve included detailed description of the issue above. Not sure I can reproduce it here without sharing my work code.
Context
Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.
- MockK version: 1.8.6
- OS: macOS High Sierra version 10.13.6
- Kotlin version: 1.2.60
- JDK version: 1.8
- JUnit version: 4
- Type of test: unit test
Failure Logs
see above description.
Stack trace
also see above description // -----------------------[ YOUR STACK TRACE ENDS HERE ] -----------------------
#### Minimal reproducible code (the gist of this issue)
see above
// -----------------------[ YOUR CODE ENDS HERE ] -----------------------
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (4 by maintainers)
Commits related to this issue
- chore(ci): fix test warning in ci by upgrade `byte-buddy` > WARN io.mockk.proxy.jvm.transformation.InliningClassTransformer - Failed to transform class > more info see > https://ci.appveyor.com/proj... — committed to alibaba/transmittable-thread-local by oldratlee 2 years ago
- chore(ci): fix test warning in ci by upgrade `byte-buddy` > WARN io.mockk.proxy.jvm.transformation.InliningClassTransformer - Failed to transform class > more info see > https://ci.appveyor.com/proj... — committed to alibaba/transmittable-thread-local by oldratlee 2 years ago
- chore(ci): fix test warning in ci by upgrade `byte-buddy` > WARN io.mockk.proxy.jvm.transformation.InliningClassTransformer - Failed to transform class > more info see > https://ci.appveyor.com/proj... — committed to alibaba/transmittable-thread-local by oldratlee 2 years ago
- chore(ci): fix test warning in ci by upgrade `byte-buddy` > WARN io.mockk.proxy.jvm.transformation.InliningClassTransformer - Failed to transform class > more info see > https://ci.appveyor.com/proj... — committed to alibaba/transmittable-thread-local by oldratlee 2 years ago
Looks alike ByteBuddy issue, would be nice to report it there