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

NPE when stub lambda since K2 #525

Open
ganadist opened this issue Aug 23, 2024 · 1 comment
Open

NPE when stub lambda since K2 #525

ganadist opened this issue Aug 23, 2024 · 1 comment

Comments

@ganadist
Copy link

ganadist commented Aug 23, 2024

  • Reproducible step
$ git clone https://github.com/ganadist/minimal-reproducible-example -b k2-stub-lambda-npe k2
Cloning into 'k2'...

$ cd k2
$ git checkout HEAD~1

# perform unittest with kotlin 1.9.23
$ ./gradlew :app:tDDUT
...
MainActivityTest > test1 STARTED

OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

MainActivityTest > test1 PASSED


$ git checkout origin/k2-stub-lambda-npe

# perform unittest with kotlin 2.0.20
$ ./gradlew :app:tDDUT

MainActivityTest > test1 STARTED

OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

MainActivityTest > test1 FAILED
    org.mockito.kotlin.MockitoKotlinException at MainActivityTest.kt:41
        Caused by: java.lang.NullPointerException at MainActivityTest.kt:41


org.mockito.kotlin.MockitoKotlinException: NullPointerException thrown when stubbing. 
   This may be due to two reasons: 
     The method you're trying to stub threw an NPE: look at the stack trace below; 
     You're trying to stub a generic method: try `onGeneric` instead.

Test code : https://github.com/ganadist/minimal-reproducible-example/blob/k2-stub-lambda-npe/app/src/test/java/com/example/myapplication/MainActivityTest.kt#L39-L42

Stacktrace on Gradle Scan

@ganadist
Copy link
Author

After switch to use onGeneric instead of on , test was passed.

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

1 participant