Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

any() matcher for java Class parameter fails with IllegalAccessError #29

Closed
a1flecke opened this issue Feb 19, 2018 · 3 comments
Closed
Assignees
Labels
Milestone

Comments

@a1flecke
Copy link

if I have a method parameter that is of type java.lang.Class<?> like:

public boolean isRegistered(Class<?> componentClass);

or in Kotlin:

fun gimmeJavaClass(klass: Class<*>): Boolean = true

then the any() matcher causes a java.lang.Class exception:

java.lang.IllegalAccessError: java.lang.Class

	at sun.reflect.GeneratedSerializationConstructorAccessor12.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.newInstance(SunReflectionFactoryInstantiator.java:48)
	at io.mockk.proxy.MockKProxyMaker.newEmptyInstance(MockKProxyMaker.java:230)
	at io.mockk.proxy.MockKProxyMaker.instance(MockKProxyMaker.java:63)
	at io.mockk.impl.instantiation.JvmInstantiator$instantiate$2.invoke(JvmInstantiator.kt:16)
	at io.mockk.impl.instantiation.AbstractInstantiator.instantiateViaInstanceFactoryRegistry(AbstractInstantiator.kt:17)
	at io.mockk.impl.instantiation.JvmInstantiator.instantiate(JvmInstantiator.kt:15)
	at io.mockk.impl.recording.states.RecordingState$matcher$signatureValue$1$1.invoke(RecordingState.kt:46)
	at io.mockk.impl.instantiation.JvmAnyValueGenerator$anyValue$1.invoke(JvmAnyValueGenerator.kt:24)
	at io.mockk.impl.instantiation.AnyValueGenerator.anyValue(AnyValueGenerator.kt:27)
	at io.mockk.impl.instantiation.JvmAnyValueGenerator.anyValue(JvmAnyValueGenerator.kt:20)
	at io.mockk.impl.recording.states.RecordingState$matcher$signatureValue$1.invoke(RecordingState.kt:45)
	at io.mockk.impl.recording.JvmSignatureValueGenerator.signatureValue(JvmSignatureValueGenerator.kt:20)
	at io.mockk.impl.recording.states.RecordingState.matcher(RecordingState.kt:44)
	at io.mockk.impl.recording.CommonCallRecorder.matcher(CommonCallRecorder.kt:47)
	at io.mockk.MockKTestSuite$1$11$1.invoke(MockKTestSuite.kt:607)
	at io.mockk.MockKTestSuite$1$11$1.invoke(MockKTestSuite.kt:10)
	at io.mockk.impl.eval.RecordedBlockEvaluator$record$block$1.invoke(RecordedBlockEvaluator.kt:22)
	at io.mockk.impl.recording.JvmAutoHinter.autoHint(JvmAutoHinter.kt:23)
	at io.mockk.impl.eval.RecordedBlockEvaluator.record(RecordedBlockEvaluator.kt:31)
	at io.mockk.impl.eval.EveryBlockEvaluator.every(EveryBlockEvaluator.kt:25)

Here is a test case:

  1. Modify your io.mockk.MockCls class in CommonCallRecorderTest to add
fun gimmeJavaClass(klass: Class<*>): Boolean = true
  1. Add this test. It will fail:
"any class" {
        every { mock.gimmeJavaClass(any()) }.returns(false)
        assertEquals(false, mock.gimmeJavaClass(Long::class.java))
    }
@oleksiyp oleksiyp added the bug label Feb 19, 2018
@oleksiyp oleksiyp self-assigned this Feb 19, 2018
oleksiyp added a commit that referenced this issue Feb 19, 2018
@oleksiyp
Copy link
Collaborator

I fixed it on master branch. Waiting for changes to be released

@oleksiyp oleksiyp added this to the 1.7.6 milestone Feb 19, 2018
@oleksiyp
Copy link
Collaborator

Version 1.7.6 released, please check and close if it fixes your issue

@a1flecke
Copy link
Author

@oleksiyp fixed. It is great to use something that is supported so well. Keep up the great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants