On 07/06/2014 00:42, Joe Darcy wrote:
Hello,
One of the classes in the Apple laf code commits the classic mistake
of override equals without also overriding hashCode. Please review my
addition of a hashCode method:
diff -r 717cad3f30fe
src/macosx/classes/com/apple/laf/AquaFileSystemModel.java
--- a/src/macosx/classes/com/apple/laf/AquaFileSystemModel.java Thu
Jun 05 23:17:05 2014 -0700
+++ b/src/macosx/classes/com/apple/laf/AquaFileSystemModel.java Fri
Jun 06 16:41:20 2014 -0700
@@ -365,8 +365,13 @@
public boolean equals(final Object other) {
final SortableFile otherFile = (SortableFile)other;
return otherFile.fFile.equals(fFile);
}
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(fFile);
+ }
}
class LoadFilesThread extends Thread {
Vector<Runnable> queuedTasks = new Vector<Runnable>();
Since the equals function is based on the fFile field, I made the
hashCode based on that field as well. If fFile happens to be null
(there is no null-check in the constructor), Objects.hashCode will
return 0; otherwise, the hash of fFile will be returned.
This looks right to me.
-Alan.