Skip to content

Regression from StrictNullChecks to NewStrictNullChecks #976

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

Closed
4 tasks done
DavidRigglemanININ opened this issue May 2, 2025 · 3 comments
Closed
4 tasks done

Regression from StrictNullChecks to NewStrictNullChecks #976

DavidRigglemanININ opened this issue May 2, 2025 · 3 comments
Labels

Comments

@DavidRigglemanININ
Copy link
Contributor

Search before asking

  • I searched in the issues and found nothing similar.
  • I have confirmed that the same problem is not reproduced if I exclude the KotlinModule.
  • I searched in the issues of databind and other modules used and found nothing similar.
  • I have confirmed that the problem does not reproduce in Java and only occurs when using Kotlin and KotlinModule.

Describe the bug

There appears to be a regression from StrictNullChecks to NewStrictNullChecks where null values are now allowed in lists if the null value was a result of a type conversion failure (such as a List where a string was passed that is not parseable as an Int)

To Reproduce

data class PrimitiveList(val list: List<Int>)

@Test // PASSES
fun strictNullChecks() {
    val om = ObjectMapper(JsonFactory())
    om.registerModule(KotlinModule.Builder().enable(KotlinFeature.StrictNullChecks).build())
    assertThatException().isThrownBy {
        om.readValue("""{"list": ["", "1"] }""".toByteArray(), PrimitiveList::class.java)
    }
}

@Test // FAILS because no exception is thrown
fun newStrictNullChecksRegression() {
    val om = ObjectMapper(JsonFactory())
    om.registerModule(KotlinModule.Builder().enable(KotlinFeature.NewStrictNullChecks).build())
    assertThatException().isThrownBy {
        om.readValue("""{"list": ["", "1"] }""".toByteArray(), PrimitiveList::class.java)
    }
}

Expected behavior

An exception is thrown rather a null value inserted that will lead to a runtime NPE at a later point

Versions

Kotlin:
Jackson-module-kotlin: 2.19.0
Jackson-databind: 2.19.0

Additional context

No response

@k163377
Copy link
Contributor

k163377 commented May 3, 2025

@DavidRigglemanININ
Thank you for trying out the new feature so quickly.
This was due to a bug in databind and I have submitted a separate issue.
FasterXML/jackson-databind#5139

This is closed because it is not an issue caused by kotlin-module (however, the submitted test case will be added to the repository later).

@k163377 k163377 closed this as completed May 3, 2025
@DavidRigglemanININ
Copy link
Contributor Author

Thanks for the quick response. So most likely it'll be fixed in 2.19.1 when databind gets released?

@k163377
Copy link
Contributor

k163377 commented May 3, 2025

I have submitted a fix and if all goes well, it will be released in 2.19.1.
FasterXML/jackson-databind#5140

k163377 added a commit to k163377/jackson-module-kotlin that referenced this issue May 4, 2025
@k163377 k163377 mentioned this issue May 4, 2025
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