With signatures of
fun and(filters: Iterable<Bson?>): Bson
and
and(vararg filters: Bson?): Bson
, I'd expect the function to correctly handle null values. But as they are passed directly to the Java implementation which only checks that the list itself is not null, an NPE is thrown when the filter is converted to a BsonDocument and filters contains any null value:
for (Bson filter : filters) { clauses.add(filter.toBsonDocument(documentClass, codecRegistry)); }
Possible solutions:
- Filter null values, like KMongo does (https://github.com/Litote/kmongo/blob/master/kmongo-property/src/main/kotlin/org/litote/kmongo/Filters.kt#L179)
- Change the signatures to only allow non-nullable `Bson` values