Skip to content

Instantly share code, notes, and snippets.

@aajisaka
Created December 1, 2016 13:41
Show Gist options
  • Save aajisaka/15951638a6e56739baafe12367b5a4b6 to your computer and use it in GitHub Desktop.
Save aajisaka/15951638a6e56739baafe12367b5a4b6 to your computer and use it in GitHub Desktop.
JDK-9045797 reproduce
import java.io.File;
import java.io.FileWriter;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.FileTime;
public class Test {
public static void main(String args[]) throws Exception {
// create a non-empty file.
File file = new File("test.txt");
file.createNewFile();
FileWriter writer = new FileWriter(file);
writer.write("test\n");
writer.close();
Path path = file.toPath();
BasicFileAttributeView view =
Files.getFileAttributeView(path, BasicFileAttributeView.class);
// set atime to 1234500
view.setTimes(null, FileTime.fromMillis(1234500), null);
// set mtime to 3456700, atime should be kept
view.setTimes(FileTime.fromMillis(3456700), null, null);
FileTime atimeAfter = view.readAttributes().lastAccessTime();
// atime should be 1234500.
System.out.println("atime: " + atimeAfter.toMillis());
if (atimeAfter.toMillis() != 1234500) {
throw new Exception("atime is updated wrongly.");
}
}
}
@aajisaka
Copy link
Author

aajisaka commented Dec 1, 2016

$ javac Test.java
$ java Test

Exception is thrown on my local MacBook Air.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment