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

java.lang.NullPointerException: anyObject() must not be null #509

Open
ChameleonTartu opened this issue Dec 15, 2023 · 1 comment
Open

Comments

@ChameleonTartu
Copy link

I am working with Kotlin, and this NullPointerException creates a lot of headaches.

The return value is non-nullable based on my research around the anyObject() functionality. I propose adding a method anyObjectOrNull() similar to Mockito.anyOrNull() from the mockito-kotlin extension.

Below is a reproduction of this issue:

Relevant StackOverflow post

Is there anything possible to do? I can potentially contribute to this issue as it will significantly help me in my apps.

@josephlbarnett
Copy link

josephlbarnett commented May 13, 2024

fwiw, we implemented a number of probably-leaky-abstractions/hacks around this here: https://github.com/trib3/leakycauldron/blob/main/testing/src/main/kotlin/com/trib3/testing/LeakyMock.kt

@henri-tremblay possibly a separate issue, but also recently noticed that the NPE leaves easymock in a bad state. eg, in https://github.com/trib3/leakycauldron/blob/main/testing/src/test/kotlin/com/trib3/testing/LeakyMockTest.kt#L148-L156 , if this test runs BEFORE other tests, it messes them up and they fail with something like IllegalState 1 matchers expected, 3 recorded., I'm assuming because the mock methods don't get called and close off the matcher invocation?

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

No branches or pull requests

2 participants