Skip to content

Kotlin invocation of Java method returning wrapper null value causes NullPointerException #2870

@tbolier

Description

@tbolier

Describe the bug

When I have a Java class with a property nullable type Double.
And from a Kotlin test I try to assert that property value with: assertThat(dataClass.nullableProperty).isNull()

It will throw a: "java.lang.NullPointerException:class.nullableProperty must not be null"

image
image

  • assertj core version: 3.23.1
  • java version: 17
  • test framework version: JUnit 5.8.2

Test case reproducing the bug

Add a test case showing the bug that we can run

package io.tbolier.test

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test

class AssertJIssue {
    @Test
    fun assertNullablePropertyKotlin() {
        val dataClass = Data(null)
        assertThat(dataClass.nullableProperty).isNull()
    }

    @Test
    fun assertNullablePropertyJava() {
        val dataClass = JavaData(null)
        assertThat(dataClass.nullableProperty).isNull()
    }
}

data class Data(val nullableProperty: Double?)

package io.tbolier.test
record JavaData(Double nullableProperty) {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    event: Hack.Commit.PushA topic worked on during a Hack.Commit.Push eventlanguage: KotlinAn issue related to using AssertJ with Kotlinstatus: out of scopeAn issue we don't think should be solved in AssertJ

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions