From 47dc58fd7eaa26baa3014f585cee390b202d8c3f Mon Sep 17 00:00:00 2001 From: Sikandar Ali Awan Date: Mon, 1 Jul 2024 15:47:09 +0200 Subject: [PATCH 1/3] Fixed the bug, a null able list does not work If there is a nullable list with values, the implementation should check it instead of wrapping the nullable list (even if it has values) into another newly created list by the Criteria class. if (!filter.ids.isNullOrEmpty()) criteria.and("id").`in`(filter.ids) -> {"id" : { "$in" : [["667e8b8af76f17213e4d4280"]]}} if (!filter.ids.isNullOrEmpty()) criteria.and("id").`in`(filter.ids!!) -> {"id" :{ "$in" : ["667e8b8af76f17213e4d4280"]}} --- .../org/springframework/data/mongodb/core/query/Criteria.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java index fc25e15c0c..ac8e101623 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java @@ -315,7 +315,7 @@ public Criteria gte(Object value) { * @see MongoDB Query operator: $in */ public Criteria in(Object... values) { - if (values.length > 1 && values[1] instanceof Collection) { + if (values.length > 0 && values[1] instanceof Collection) { throw new InvalidMongoDbApiUsageException( "You can only pass in one argument of type " + values[1].getClass().getName()); } From 232b8a1d7baa3a6760a901053348ea1639ef6c1b Mon Sep 17 00:00:00 2001 From: Sikandar Ali Awan Date: Mon, 1 Jul 2024 16:14:57 +0200 Subject: [PATCH 2/3] Fixed the criteria in method If there is a nullable list with values, the implementation should check it instead of wrapping the nullable list (even if it has values) into another newly created list by the Criteria class. Existing Code: if (!filter.ids.isNullOrEmpty()) criteria.and("id").in(filter.ids) Output: {"id" : { "$in" : [["667e8b8af76f17213e4d4280"]]}} Wrong Code: if (!filter.ids.isNullOrEmpty()) criteria.and("id").in(filter.ids!!) Required !! Output: {"id" :{ "$in" : ["667e8b8af76f17213e4d4280"]}} Correct After Fix Code: if (!filter.ids.isNullOrEmpty()) criteria.and("id").in(filter.ids) With and Without !! Output: {"id" : { "$in" : ["667e8b8af76f17213e4d4280"]}} Correct --- .../org/springframework/data/mongodb/core/query/Criteria.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java index ac8e101623..4133d432e1 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java @@ -315,7 +315,7 @@ public Criteria gte(Object value) { * @see MongoDB Query operator: $in */ public Criteria in(Object... values) { - if (values.length > 0 && values[1] instanceof Collection) { + if (values.length > 0 && values[0] instanceof Collection) { throw new InvalidMongoDbApiUsageException( "You can only pass in one argument of type " + values[1].getClass().getName()); } From 2009044007f03060fa44cf92452d686b38bbe684 Mon Sep 17 00:00:00 2001 From: Sikandar Ali Awan Date: Mon, 1 Jul 2024 16:16:51 +0200 Subject: [PATCH 3/3] Fixed the bug, a null able list does not work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If there is a nullable list with values, the implementation should check it instead of wrapping the nullable list (even if it has values) into another newly created list by the Criteria class. Existing Code: if (!filter.ids.isNullOrEmpty()) criteria.and("id").in(filter.ids) Output: {"id" : { "$in" : [["667e8b8af76f17213e4d4280"]]}} Wrong Code: if (!filter.ids.isNullOrEmpty()) criteria.and("id").in(filter.ids!!) Required !! Output: {"id" :{ "$in" : ["667e8b8af76f17213e4d4280"]}} Correct After Fix Code: if (!filter.ids.isNullOrEmpty()) criteria.and("id").in(filter.ids) With and Without !! Output: {"id" : { "$in" : ["667e8b8af76f17213e4d4280"]}} Correct You have read the Spring Data contribution guidelines. You use the code formatters provided here and have them applied to your changes. Don’t submit any formatting related changes. You submit test cases (unit or integration tests) that back your changes. You added yourself as author in the headers of the classes you touched. Amend the date range in the Apache license header if needed. For new types, add the license header (copy from another file and set the current year only). --- .../org/springframework/data/mongodb/core/query/Criteria.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java index 4133d432e1..7d1bbc6c16 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Criteria.java @@ -317,7 +317,7 @@ public Criteria gte(Object value) { public Criteria in(Object... values) { if (values.length > 0 && values[0] instanceof Collection) { throw new InvalidMongoDbApiUsageException( - "You can only pass in one argument of type " + values[1].getClass().getName()); + "You can only pass in one argument of type " + values[0].getClass().getName()); } criteria.put("$in", Arrays.asList(values)); return this;