Skip to content

Null validation produces a false negative on nullable collections that contain null #1

@robpridham

Description

@robpridham

If you run the null validation in containsIllegalNullValues on a nullable list, e.g.:

val nullableListWithNull = listOf<String?>(null)

then it will return false, because on iterating through the list, element is null. This may seem like an odd scenario but we experience it when using Gson with a custom deserialiser that ignores certain elements, for which it returns null.

I did look at whether it was possible to improve on this, e.g. examine the return type of the collection's iterator to see if isMarkedNullable would be true, but I couldn't find a working solution. I think this a product of how Kotlin does generics, e.g. https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.reflect/-k-type/is-marked-nullable.html

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