Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix same hashCodes an different queries with include and exclude #4831

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the fix, the test above failed.
image

}
}