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

(fs) BasicFileAttributes is unable to return a file creation time

XMLWordPrintable

    • b01
    • x86_64
    • linux

      ADDITIONAL SYSTEM INFORMATION :
      OS = RHEL 8.9.20240221.0
      Openshift Kubernetes
      JDK 21.0.3 + 21.0.2 + 21.0.1 + 17.0.11 + 17.0.10

      A DESCRIPTION OF THE PROBLEM :
      It appears BasicFileAttributes is no longer able to return the creation time of a file instead returning "1970-01-01T00:00:00Z".
      I recently migrated from JDK 17 to 21 which was when I noticed this issue as it used to work. This is however present in both JDK17 + 21.

      Upon investigation (keeping all things equal and just changing the JDK verison), this issue was introduced in JDK21.0.2/JDK17.0.11. It seems both JDK21.0.1/17.0.10 return the correct creation date for the target file.

      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.

      REGRESSION : Last worked in version 21

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a pod running RHEL 8.9.20240221.0
      Run the following commands:
      jshell
      import java.nio.file.attribute.BasicFileAttributes;
      BasicFileAttributes attr = Files.readAttributes(Path.of("<your-file>"), BasicFileAttributes.class);
      attr.creationTime().toInstant();

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The correct creation time of the file e.g. 2024-05-01T22:25:7557213Z
      ACTUAL -
      The default creation time of 1970-01-01T00:00:00Z as per the documentation for creationTime() as a default value

      ---------- BEGIN SOURCE ----------
      jshell
      import java.nio.file.attribute.BasicFileAttributes;
      BasicFileAttributes attr = Files.readAttributes(Path.of("<your-file>"), BasicFileAttributes.class);
      attr.creationTime().toInstant();
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No known workaround except using older JDK versions

      FREQUENCY : always


            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: