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

(file spec) Incompatible File.lastModified() and setLastModified() for negative time

XMLWordPrintable

    • b175
    • x86
    • windows_xp
    • Not verified

        A DESCRIPTION OF THE REQUEST :
        File.lastModified() returns a negative value when the timestamp is before the epoch. However, File.setLastModified() does not allow negative timestamps --- the specs require that it throws an IllegalArgumentException if the argument is negative. This behavior is incompatible.

        JUSTIFICATION :
        Violates our assumption on how the pair of methods should work --- a valid return value from lastModified() should be a valid argument for setLastModified(). This poses problems when synchronizing files.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        setLastModified() should accept negative values.
        ACTUAL -
        setLastModified() throws an IllegalArgumentException if the argument is negative.

        ---------- BEGIN SOURCE ----------
        /* create the file "test" with a last modified timestamp that is before the epoch (i.e. 1970), e.g. by using touch */

        public static void main(String[] args)
        {
        File f = new File("test");
        long time = f.lastModified();
        f.setLastModified(time); /* throws an IllegalArgumentException */
        }
        ---------- END SOURCE ----------

              bpb Brian Burkhalter
              ryeung Roger Yeung (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: