< prev index next >

src/java.base/share/classes/java/io/File.java

Print this page

        

@@ -932,11 +932,13 @@
      * @return  A <code>long</code> value representing the time the file was
      *          last modified, measured in milliseconds since the epoch
      *          (00:00:00 GMT, January 1, 1970), or <code>0L</code> if the
      *          file does not exist or if an I/O error occurs; the value may
      *          be negative in which case its absolute value indicates the
-     *          number of milliseconds before the epoch
+     *          number of milliseconds before the epoch; if the last-modified
+     *          time is the epoch, the value will be unity (<code>1</code>)
+     *          so as to avoid ambiguity with the case of a non-existent file
      *
      * @throws  SecurityException
      *          If a security manager exists and its {@link
      *          java.lang.SecurityManager#checkRead(java.lang.String)}
      *          method denies read access to the file

@@ -947,11 +949,22 @@
             security.checkRead(path);
         }
         if (isInvalid()) {
             return 0L;
         }
-        return fs.getLastModifiedTime(this);
+        long lastModifiedTime = fs.getLastModifiedTime(this);
+
+        //
+        // In the infinitesimally probable event that the last-modified time
+        // of the file is the epoch (zero), return unity instead so as to avoid
+        // ambiguity with the case of a non-existent file which returns zero.
+        //
+        if (lastModifiedTime == 0) {
+            lastModifiedTime = 1;
+        }
+
+        return lastModifiedTime;
     }
 
     /**
      * Returns the length of the file denoted by this abstract pathname.
      * The return value is unspecified if this pathname denotes a directory.
< prev index next >