Skip to content

Commit

Permalink
Fix same hashCodes an different queries with include and exclude
Browse files Browse the repository at this point in the history
  • Loading branch information
13wjdgk committed Nov 10, 2024
1 parent 5b1b0a4 commit 65257f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @author Mark Paluch
* @author Owen Q
* @author Kirill Egorov
* @author GaEun Kim
*/
public class Field {

Expand Down Expand Up @@ -286,7 +287,7 @@ public boolean equals(@Nullable Object o) {
@Override
public int hashCode() {

int result = ObjectUtils.nullSafeHashCode(criteria);
int result = ObjectUtils.nullSafeHashCode(criteria.toString());
result = 31 * result + ObjectUtils.nullSafeHashCode(slices);
result = 31 * result + ObjectUtils.nullSafeHashCode(elemMatches);
result = 31 * result + ObjectUtils.nullSafeHashCode(positionKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @author Owen Q
* @author Mark Paluch
* @author Kirill Egorov
* @author GaEun Kim
*/
class FieldUnitTests {

Expand Down Expand Up @@ -85,4 +86,18 @@ void overriddenExclusionMethodsCreateEqualFields() {

assertThat(left).isEqualTo(right);
}

@Test
void assertDifferentHashCodesForExcludeAndIncludeQueries() {

Query queryWithExclude = new Query();
queryWithExclude.fields().exclude("key1");
queryWithExclude.fields().exclude("key2");

Query queryWithInclude = new Query();
queryWithInclude.fields().include("key1");
queryWithInclude.fields().include("key2");

assertThat(queryWithExclude.hashCode()).isNotEqualTo(queryWithInclude.hashCode());
}
}

0 comments on commit 65257f2

Please sign in to comment.