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

File.delete() should throw IOException instead of returning false

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.2
    • core-libs
    • x86
    • windows_nt

      Name: rmT116609 Date: 11/12/2003


      A DESCRIPTION OF THE REQUEST :
      if java.io.File.delete() fails, the result value is false. there is no further information about the reason why it failed. it would be better that this method would throw a IOException with the reason why it failed. (in my case, it failed because another process still had a reference to the file.)

      JUSTIFICATION :
      with the current behaviour (just return false if delete() failed) there is no information why the deletion failed.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      e.g. if the file can't be deleted because it's still in access by another process, don't just return false but throw an IOException with the reason (e.g. "File is still referenced by another process.")
      ACTUAL -
      the method just returns false.

      ---------- BEGIN SOURCE ----------
      File file = new File("readme.txt");
      boolean result = file.delete();
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      you have to guess the reason why delete() failed.
      (Incident Review ID: 225294)
      ======================================================================

            alanb Alan Bateman
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: