8380848: jdk/nio/zipfs/ZipFSTester.java fails after JDK-8378884

Reviewed-by: lancea, syan
This commit is contained in:
Justin Lu 2026-03-30 16:49:09 +00:00
parent ab83702428
commit 73501b274f

View File

@ -21,6 +21,7 @@
* questions.
*/
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
@ -97,14 +98,21 @@ public class ZipFSTester {
// create JAR file for test, actual contents don't matter
static Path jarFile;
static String[] jarContents = new String[]{
"META-INF/MANIFEST.MF",
"dir1/foo",
"dir2/bar",
"dir1/dir3/fooo"
};
@BeforeAll
static void setup() throws Exception {
jarFile = Utils.createJarFile("tester.jar",
"META-INF/MANIFEST.MF",
"dir1/foo",
"dir2/bar",
"dir1/dir3/fooo");
jarFile = Utils.createJarFile("tester.jar", jarContents);
}
@AfterAll
static void cleanup() throws IOException {
Files.deleteIfExists(jarFile);
}
@Test
@ -583,19 +591,18 @@ public class ZipFSTester {
// test file stamp
@Test
void testTime() throws Exception {
var jar = Utils.createJarFile(System.currentTimeMillis() + ".jar", jarContents);
BasicFileAttributes attrs = Files
.getFileAttributeView(jarFile, BasicFileAttributeView.class)
.getFileAttributeView(jar, BasicFileAttributeView.class)
.readAttributes();
// create a new filesystem, copy this file into it
Map<String, Object> env = new HashMap<String, Object>();
env.put("create", "true");
Path fsPath = getTempPath();
try (FileSystem fs = newZipFileSystem(fsPath, env)) {
try (FileSystem fs = FileSystems.newFileSystem(fsPath, Map.of("create", "true"))) {
System.out.println("test copy with timestamps...");
// copyin
Path dst = getPathWithParents(fs, "me");
Files.copy(jarFile, dst, COPY_ATTRIBUTES);
checkEqual(jarFile, dst);
Path dst = fs.getPath("me");
Files.copy(jar, dst, COPY_ATTRIBUTES);
checkEqual(jar, dst);
System.out.println("mtime: " + attrs.lastModifiedTime());
System.out.println("ctime: " + attrs.creationTime());
System.out.println("atime: " + attrs.lastAccessTime());
@ -608,14 +615,15 @@ public class ZipFSTester {
System.out.println("atime: " + dstAttrs.lastAccessTime());
// 1-second granularity
assertFalse(attrs.lastModifiedTime().to(TimeUnit.SECONDS) !=
dstAttrs.lastModifiedTime().to(TimeUnit.SECONDS) ||
attrs.lastAccessTime().to(TimeUnit.SECONDS) !=
dstAttrs.lastAccessTime().to(TimeUnit.SECONDS) ||
attrs.creationTime().to(TimeUnit.SECONDS) !=
dstAttrs.creationTime().to(TimeUnit.SECONDS), "Timestamp Copy Failed!");
assertEquals(attrs.lastModifiedTime().to(TimeUnit.SECONDS),
dstAttrs.lastModifiedTime().to(TimeUnit.SECONDS), "Last modified time incorrect");
assertEquals(attrs.lastAccessTime().to(TimeUnit.SECONDS),
dstAttrs.lastAccessTime().to(TimeUnit.SECONDS), "Last access time incorrect");
assertEquals(attrs.creationTime().to(TimeUnit.SECONDS),
dstAttrs.creationTime().to(TimeUnit.SECONDS), "Last creation time incorrect");
} finally {
Files.delete(fsPath);
Files.deleteIfExists(fsPath);
Files.deleteIfExists(jar);
}
}