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

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

    Details

    • Subcomponent:
    • Resolved In Build:
      b175
    • CPU:
      x86
    • OS:
      windows_xp
    • Verification:
      Not verified

      Backports

        Description

        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 ----------

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: