From a481636429fd92af83a8226c0c51ae1cbf13afe3 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Wed, 9 Jun 2021 12:06:43 +0200 Subject: [PATCH] Polishing. Add nullability annotation. Return early on null value conversion. See #3633 Original pull request: #3643. --- .../data/mongodb/core/convert/QueryMapper.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java index 65f66ec4c..584081556 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/convert/QueryMapper.java @@ -445,6 +445,10 @@ public class QueryMapper { } } + if (value == null) { + return null; + } + if (isNestedKeyword(value)) { return getMappedKeyword(new Keyword((Bson) value), documentField.getPropertyEntity()); } @@ -711,7 +715,7 @@ public class QueryMapper { * @param candidate * @return */ - protected boolean isNestedKeyword(Object candidate) { + protected boolean isNestedKeyword(@Nullable Object candidate) { if (!(candidate instanceof Document)) { return false; @@ -759,6 +763,7 @@ public class QueryMapper { * @param value the actual value. Can be {@literal null}. * @return the potentially converted target value. */ + @Nullable private Object applyFieldTargetTypeHintToValue(Field documentField, @Nullable Object value) { if (value == null || documentField.getProperty() == null || !documentField.getProperty().hasExplicitWriteTarget()) {