--- /dev/null 2017-05-22 13:15:57.000000000 -0700 +++ new/test/java/io/File/FileTimeAtEpoch.java 2017-05-22 13:15:57.000000000 -0700 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8180767 + * @summary Ensure that lastModified() returns unity for files modified at epoch + */ + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.attribute.FileTime; +import java.util.concurrent.TimeUnit; + +public class FileTimeAtEpoch { + public static void main(String[] args) throws Throwable { + String dirname = System.getProperty("test.dir", "."); + System.out.format("Working directory: %s%n", dirname); + File dir = new File(dirname); + File file = File.createTempFile("epoch", ".txt"); + System.out.format("Test file: %s%n", file.getAbsolutePath()); + FileTime epoch = FileTime.from(0L, TimeUnit.MILLISECONDS); + Path path = file.toPath(); + FileTime current = Files.getLastModifiedTime(path); + System.out.format("Current last-modified time: %s%n", + current.toString()); + Files.setLastModifiedTime(path, epoch); + FileTime updated = Files.getLastModifiedTime(path); + System.out.format("Updated last-modified time: %s%n", + updated.toString()); + long lastModified = file.lastModified(); + if (lastModified != 1L) { + throw new RuntimeException + ("Expected last-modified time of 1 but obtained " + + lastModified); + } + } +}