Closed
Description
In JSON queries when you have a nullable value for an object id parameter, A null pointer exception will be thrown. It may seem reasonable but it's not suitable for a case where you want to implement a search function using nullable parameter values. If the value is null you expect null to be replaced with object id.
My case :
@Query("{ $and : [ { $or : [ { $expr: { $eq: ['?0', 'null'] } } , { movie_id : ObjectId(?0) } ] }, { $or : [ { $expr: { $eq: ['?1', 'null'] } } , { email : ?1 } ] } ] }")
List<Comment> search(String movieId, String email, Pageable pageable);
The exception :
java.lang.NullPointerException: Cannot invoke "Object.toString()" because the return value of "org.springframework.data.mongodb.util.json.ParameterBindingJsonReader$BindableValue.getValue()" is null
at org.springframework.data.mongodb.util.json.ParameterBindingJsonReader.readStringFromExtendedJson(ParameterBindingJsonReader.java:1428) ~[spring-data-mongodb-4.0.0.jar:4.0.0]
At least a better exception with a good message should be thrown because it takes some time for me to find out the exception reason