-
Notifications
You must be signed in to change notification settings - Fork 112
Fix ResolvedKeySpacePath.equals and hashCode #3591
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
base: main
Are you sure you want to change the base?
Changes from all commits
f153d1e
f6bdc40
ffc000c
a84876b
c35d1d4
a070102
a64373e
0720af5
f2691b4
89174b8
98d4b03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,27 +276,22 @@ public boolean equals(Object obj) { | |
} | ||
KeySpacePath that = (KeySpacePath) obj; | ||
|
||
// Check that the KeySpaceDirectories of the two paths are "equal enough". | ||
// Even this is probably overkill since the isCompatible check in KeySpaceDirectory | ||
// will keep us from doing anything too bad. We could move this check into KeySpaceDirectory | ||
// but comparing two directories by value would necessitate traversing the entire directory | ||
// tree, so instead we will use a narrower definition of equality here. | ||
boolean directoriesEqual = Objects.equals(this.getDirectory().getKeyType(), that.getDirectory().getKeyType()) && | ||
Objects.equals(this.getDirectory().getName(), that.getDirectory().getName()) && | ||
Objects.equals(this.getDirectory().getValue(), that.getDirectory().getValue()); | ||
// We don't care whether the two objects exist in the same hierarchy, we validate the relevant bits by comparing | ||
// parents. | ||
boolean directoriesEqual = this.getDirectory().equalsIgnoringHierarchy(that.getDirectory()); | ||
|
||
// the values might be byte[] | ||
return directoriesEqual && | ||
Objects.equals(this.getValue(), that.getValue()) && | ||
Objects.equals(this.getParent(), that.getParent()); | ||
KeySpaceDirectory.areEqual(this.getValue(), that.getValue()) && | ||
Objects.equals(this.getParent(), that.getParent()); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash( | ||
getDirectory().getKeyType(), | ||
getDirectory().getName(), | ||
getDirectory().getValue(), | ||
getValue(), | ||
KeySpaceDirectory.valueHashCode(getValue()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be the same as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only if the directory is a constant. If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In that case there may be a discrepancy where
Whereas
So it looks as if the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes, that is probably true. |
||
parent); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a defensive coding we can add
equals
andhashCode
toAnyValue
, though all reasonable implementations should use the static constant...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, but
AnyValue
is a private-nested class, soKeySpaceDirectory
is the only way to construct one, so you really shouldn't be accessing it other than via the constant.