Skip to content

NPE when stub lambda since K2 #525

Open
@ganadist

Description

@ganadist
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions