Skip to content

Commit c062c85

Browse files
author
duke
committed
Backport 828498c54b3b1089af9e076cb45f3cf3bea58e2f
1 parent 70ba5d4 commit c062c85

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

test/jdk/tools/jar/ReproducibleJar.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -66,7 +66,9 @@ public class ReproducibleJar {
6666
private static final TimeZone TZ = TimeZone.getDefault();
6767
private static final boolean DST = TZ.inDaylightTime(new Date());
6868
private static final String UNIX_2038_ROLLOVER_TIME = "2038-01-19T03:14:07Z";
69+
private static final String UNIX_EPOCH_TIME = "1970-01-01T00:00:00Z";
6970
private static final Instant UNIX_2038_ROLLOVER = Instant.parse(UNIX_2038_ROLLOVER_TIME);
71+
private static final Instant UNIX_EPOCH = Instant.parse(UNIX_EPOCH_TIME);
7072
private static final File DIR_OUTER = new File("outer");
7173
private static final File DIR_INNER = new File(DIR_OUTER, "inner");
7274
private static final File FILE_INNER = new File(DIR_INNER, "foo.txt");
@@ -231,12 +233,15 @@ static void checkFileTime(long now, long original) {
231233

232234
if (Math.abs(now - original) > PRECISION) {
233235
// If original time is after UNIX 2038 32bit rollover
234-
// and the now time is exactly the rollover time, then assume
236+
// and the now time is exactly the rollover time or UNIX epoch time, then assume
235237
// running on a file system that only supports to 2038 (e.g.XFS) and pass test
236-
if (FileTime.fromMillis(original).toInstant().isAfter(UNIX_2038_ROLLOVER) &&
237-
FileTime.fromMillis(now).toInstant().equals(UNIX_2038_ROLLOVER)) {
238-
System.out.println("Checking file time after Unix 2038 rollover," +
239-
" and extracted file time is " + UNIX_2038_ROLLOVER_TIME + ", " +
238+
Instant originalInstant = FileTime.fromMillis(original).toInstant();
239+
Instant nowInstant = FileTime.fromMillis(now).toInstant();
240+
if (originalInstant.isAfter(UNIX_2038_ROLLOVER) &&
241+
(nowInstant.equals(UNIX_2038_ROLLOVER) ||
242+
nowInstant.equals(UNIX_EPOCH))) {
243+
System.out.println("Checking file time after Unix 2038 rollover," +
244+
" and extracted file time is " + nowInstant + ", " +
240245
" Assuming restricted file system, pass file time check.");
241246
} else {
242247
throw new AssertionError("checkFileTime failed," +

0 commit comments

Comments
 (0)