Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8338767

(fs) BasicFileAttributes.creationTime() falls back to epoch if birth time is unavailable (Linux)

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P3 P3
    • 23-pool, 24
    • core-libs
    • None
    • behavioral
    • minimal
    • Code which depends on the new (JDK 22) behavior of creationTime() could observe the difference in behavior.
    • Java API
    • Implementation

      Summary

      On Linux, modify java.nio.file.attributes.BasicFileAttributes.creationTime() to return the last modified time instead of 0, the epoch, if the birth timestamp of the file is unavailable.

      Problem

      The change which resolved JDK-8316304 added support for obtaining the file creation time from the birth timestamp. Prior to this change, the last modified time had been returned for the creation time. After this change, if the birth timestamp is unavailable, for example if it is not supported by the file system even though the operating system supports it, then the epoch (0) is returned for the creation time. This can, and in fact was observed to, cause problems in situations which relied on the old behavior.

      Solution

      Return the last modified time instead of zero for the creation time when the birth timestamp is unavailable.

      Specification

      There are no changes to the specification of BasicFileAttributes.creationTime(), but its current wording is provided here for convenience. Note that both behaviors, returning the last modified time or the epoch, are within the bounds of the specification.

      Returns the creation time. The creation time is the time that the file was created.

      If the file system implementation does not support a time stamp to indicate the time when the file was created then this method returns an implementation specific default value, typically the last-modified-time or a FileTime representing the epoch (1970-01-01T00:00:00Z).

            bpb Brian Burkhalter
            bpb Brian Burkhalter
            Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: