mirror of
https://github.com/openjdk/jdk.git
synced 2026-01-28 03:58:21 +00:00
8376294: ZipFile.Source.Key should not hold on to its BasicFileAttributes instance
Reviewed-by: jpai
This commit is contained in:
parent
ee2deaded8
commit
e0445c09f7
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1995, 2025, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1995, 2026, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -37,6 +37,7 @@ import java.nio.charset.Charset;
|
|||||||
import java.nio.file.InvalidPathException;
|
import java.nio.file.InvalidPathException;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.attribute.FileTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.IntFunction;
|
import java.util.function.IntFunction;
|
||||||
@ -1444,11 +1445,13 @@ public class ZipFile implements ZipConstants, Closeable {
|
|||||||
* The unique combination of these components identifies a Source of a ZipFile.
|
* The unique combination of these components identifies a Source of a ZipFile.
|
||||||
*/
|
*/
|
||||||
private static class Key {
|
private static class Key {
|
||||||
private final BasicFileAttributes attrs;
|
|
||||||
private final File file;
|
private final File file;
|
||||||
|
private final Object fileKey;
|
||||||
|
private final FileTime lastModifiedTime;
|
||||||
// the Charset that was provided when constructing the ZipFile instance
|
// the Charset that was provided when constructing the ZipFile instance
|
||||||
private final Charset charset;
|
private final Charset charset;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a {@code Key} to a {@code Source} of a {@code ZipFile}
|
* Constructs a {@code Key} to a {@code Source} of a {@code ZipFile}
|
||||||
*
|
*
|
||||||
@ -1457,7 +1460,8 @@ public class ZipFile implements ZipConstants, Closeable {
|
|||||||
* @param charset the Charset that was provided when constructing the ZipFile instance
|
* @param charset the Charset that was provided when constructing the ZipFile instance
|
||||||
*/
|
*/
|
||||||
public Key(File file, BasicFileAttributes attrs, Charset charset) {
|
public Key(File file, BasicFileAttributes attrs, Charset charset) {
|
||||||
this.attrs = attrs;
|
this.fileKey = attrs.fileKey();
|
||||||
|
this.lastModifiedTime = attrs.lastModifiedTime();
|
||||||
this.file = file;
|
this.file = file;
|
||||||
this.charset = charset;
|
this.charset = charset;
|
||||||
}
|
}
|
||||||
@ -1465,10 +1469,9 @@ public class ZipFile implements ZipConstants, Closeable {
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
long t = charset.hashCode();
|
long t = charset.hashCode();
|
||||||
t += attrs.lastModifiedTime().toMillis();
|
t += lastModifiedTime.toMillis();
|
||||||
Object fk = attrs.fileKey();
|
|
||||||
return Long.hashCode(t) +
|
return Long.hashCode(t) +
|
||||||
(fk != null ? fk.hashCode() : file.hashCode());
|
(fileKey != null ? fileKey.hashCode() : file.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1477,12 +1480,12 @@ public class ZipFile implements ZipConstants, Closeable {
|
|||||||
if (!charset.equals(key.charset)) {
|
if (!charset.equals(key.charset)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!attrs.lastModifiedTime().equals(key.attrs.lastModifiedTime())) {
|
if (!lastModifiedTime.equals(key.lastModifiedTime)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Object fk = attrs.fileKey();
|
|
||||||
if (fk != null) {
|
if (fileKey != null) {
|
||||||
return fk.equals(key.attrs.fileKey());
|
return fileKey.equals(key.fileKey);
|
||||||
} else {
|
} else {
|
||||||
return file.equals(key.file);
|
return file.equals(key.file);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user