[jdk17u-dev] RFR: 8316304: (fs) Add support for BasicFileAttributes.creationTime() for Linux

Severin Gehwolf sgehwolf at openjdk.org
Tue Aug 26 13:49:40 UTC 2025


On Thu, 25 Jan 2024 15:05:49 GMT, Severin Gehwolf <sgehwolf at openjdk.org> wrote:

> This is an unclean backport of the filesystem enhancement on Linux to use `statx` where available. The JDK 21u patch didn't apply cleanly because JDK 20+ has [JDK-8283335](https://bugs.openjdk.org/browse/JDK-8283335) which isn't needed for this backport. The relevant code has been adjusted to work without that enhancement being present (see different commits). Copyright dates needed manual adjusting and the test needed some trivial changes related to test lib and import so that it works (failed to compile on 17u).
> 
> As for the code changes in `UnixNativeDispatcher.c`, the JNI method `Java_sun_nio_fs_UnixNativeDispatcher_stat1()` returning the mode for a file/directory doesn't exist in JDK 21 (again [JDK-8283335](https://bugs.openjdk.org/browse/JDK-8283335)). Therefore, I've adjusted the code to also use `statx` where available for symmetry.
> 
> I'll follow up with the related build fix (for the test libs) in a dependent PR (JDK-8319922).
> 
> Please review!
> 
> Testing:
> - [x] GHA
> - [x] Build test on various Linux (aarch64, Alpine x64, ppc64le, x64) and Unix OSes (AIX, Mac) so as to not break the build there.
> - [x] Manual testing for `BasicFileAttributes.creationTime()`. Looks good.

> > Users already get different behaviour on say, Mac OS, Windows and Linux (with statx support) today. The former two support creationTime(), Linux does not (prior this patch).
> 
> It looks like the behavior of `BasicFileAttributes` and `BasicFileAttributeView` is now inconsistent on Linux (Apline). I can change the time using:
> 
> ```java
> BasicFileAttributeView attributes = Files.getFileAttributeView(path, BasicFileAttributeView.class);
> attributes.setTimes(time, time, time);
> ```
> 
> And the 3d param is called `createTime`. But apparently it sets a different attribute than what we get using:
> 
> ```java
> FileTime actual = Files.readAttributes(path, BasicFileAttributes.class).creationTime();
> ```
> 
> Tried with OpenJDK 24.

Updating of the creation time (birth time) is not supported on Linux as far as I know. So you'd get the creation time when the file was originally created, not when `setTimes()` has been called.

-------------

PR Comment: https://git.openjdk.org/jdk17u-dev/pull/2175#issuecomment-3224252147


More information about the jdk-updates-dev mailing list