JDK-6939260 : (fs) BasicFileAttributes.lastModifiedTime() should return last modified time with higher precision
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 6u15
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: linux_ubuntu
  • CPU: x86
  • Submitted: 2010-03-30
  • Updated: 2013-04-12
  • Resolved: 2013-01-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b75Fixed
Description
FULL PRODUCT VERSION :
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
Java HotSpot(TM) 64-Bit Server VM (build 14.1-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Linux universe 2.6.31-20-generic #58-Ubuntu SMP Fri Mar 12 04:38:19 UTC 2010 x86_64 GNU/Linux


EXTRA RELEVANT SYSTEM CONFIGURATION :
ext4 hard disk partition


A DESCRIPTION OF THE PROBLEM :
incorrect precision of lastModified() of java.io.File on Ubuntu x64 Linux

According to https://ext4.wiki.kernel.org/index.php/Ext4_Howto#Inode-related_features

ext4 support time precision up to nanosecond

According to http://java.sun.com/javase/6/docs/api/java/io/File.html#lastModified%28%29

the lastModified() function support resolution up to microsecond.

In fact, the function also return '000' at the end of number, which is inaccurate

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
list a directory by the following shell command (will show the full timestamp)

ls -la --full-time /

write a simple java program to display the lastModified time of any file

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
lastModified time up to microseconds should be shown
ACTUAL -
The end of the number is always 000, which is inaccurate

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.io.*;

public class test {

    public static void main(String[] args) throws Throwable {
        String path="/etc/fstab";
        System.out.println("File: "+path+" , last modified: "+Long.toString(new java.io.File(path).lastModified()));
    }

}
---------- END SOURCE ----------

Comments
verified in b85
12-04-2013

I've moved this issue to java.nio because it is straight-forward to support in the new file system API (it's not possible to support this with java.io.File because it specifies that the last modified time is returned in milliseconds). In the new file system API then this just becomes an implementation change as the API already allow for the file times in any precision.
25-10-2012