8317678: Fix up hashCode() for ZipFile.Source.Key

Reviewed-by: lancea, alanb, jpai
This commit is contained in:
Sean Coffey 2023-10-23 17:12:41 +00:00
parent 69c0ae23a3
commit 8d9a4b43f4
3 changed files with 189 additions and 1 deletions

View file

@ -1395,6 +1395,13 @@ public class ZipFile implements ZipConstants, Closeable {
private int[] table; // Hash chain heads: indexes into entries
private int tablelen; // number of hash heads
/**
* A class representing a key to a zip file. A key is based
* on the file key if available, or the path value if the
* file key is not available. The key is also based on the
* file's last modified time to allow for cases where a zip
* file is re-opened after it has been modified.
*/
private static class Key {
final BasicFileAttributes attrs;
File file;
@ -1409,7 +1416,9 @@ public class ZipFile implements ZipConstants, Closeable {
public int hashCode() {
long t = utf8 ? 0 : Long.MAX_VALUE;
t += attrs.lastModifiedTime().toMillis();
return ((int)(t ^ (t >>> 32))) + file.hashCode();
Object fk = attrs.fileKey();
return Long.hashCode(t) +
(fk != null ? fk.hashCode() : file.hashCode());
}
public boolean equals(Object obj) {