BasicFileAttributeView#setTimes not working since JDK v21.0.2

  Kiến thức lập trình

I have a JUnit test which is trying to modify a folder creation time :

BasicFileAttributeView attribsView = Files.getFileAttributeView(myFolder.toPath(), BasicFileAttributeView.class);
FileTime epoch = FileTime.fromMillis(0);
attribsView.setTimes(epoch, epoch, epoch);

This code is working well until JDK v21.0.1. But since JDK v21.0.2, the setTimes method does not modify the creationTime attribute anymore, and my test fails. However, I’ve seen this bug. In the bug description, this is confirmed that :

I also noticed this issue when using attributes.setTimes(time, time, time); to set the file times. This call appears to longer work like it used to.

However, this bug has been declared as resolved and “not an issue”.

So, if it is the intended behavior, what is the right way to modify a file/folder creationTime attribute since JDK 21.0.2 ? Can we still use the BasicFileAttributeView#setTimes method as before ?

Please explain, I am confused. Thanks.

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website