<Swing Dev> JDK 9 RFR of JDK-8046271: Fix overrides lint warnings in Apple laf code
Joe Darcy
joe.darcy at oracle.com
Fri Jun 6 23:42:58 UTC 2014
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.
Thanks,
-Joe
More information about the swing-dev
mailing list