RFR: 8317678: Fix up hashCode() for ZipFile.Source.Key [v2]

Alan Bateman alanb at openjdk.org
Tue Oct 10 12:59:30 UTC 2023


On Tue, 10 Oct 2023 12:46:22 GMT, Sean Coffey <coffeys at openjdk.org> wrote:

>> Fix up java.util.zip.ZipFile$Source hashCode() impl so that duplicate Source objects aren't created for the same zip file.
>
> Sean Coffey has updated the pull request incrementally with one additional commit since the last revision:
> 
>   incorporate review comments

src/java.base/share/classes/java/util/zip/ZipFile.java line 1423:

> 1421:                 try {
> 1422:                     return System.getSecurityManager() != null ?
> 1423:                         AccessController.doPrivileged((PrivilegedExceptionAction<File>) file::getCanonicalFile) :

I think you'll have to cleanly separate the SM and no-SM case because of the exception handling, then you can use `PrivilegedExceptionAction<File> pae = file::getCanonicalFile`.

src/java.base/share/classes/java/util/zip/ZipFile.java line 1426:

> 1424:                         file.getCanonicalFile();
> 1425:                 } catch (PrivilegedActionException e) {
> 1426:                     throw new IOException(e);

The IOException to throw is PAE's cause, meaning you need to unwrap.

src/java.base/share/classes/java/util/zip/ZipFile.java line 1451:

> 1449:                     if (!attrs.lastModifiedTime().equals(key.attrs.lastModifiedTime())) {
> 1450:                         return false;
> 1451:                     }

The question in the previous comment is why is the last modified time used here, I think you have to dig into why it is used by equals.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/16115#discussion_r1352471731
PR Review Comment: https://git.openjdk.org/jdk/pull/16115#discussion_r1352468697
PR Review Comment: https://git.openjdk.org/jdk/pull/16115#discussion_r1352475053


More information about the core-libs-dev mailing list