Created
December 1, 2016 13:41
-
-
Save aajisaka/15951638a6e56739baafe12367b5a4b6 to your computer and use it in GitHub Desktop.
JDK-9045797 reproduce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exception is thrown on my local MacBook Air.