Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4952996
Votes 14
Synopsis File.delete() should throw IOException instead of returning false
Category java:classes_io
Reported Against 1.4.2
Release Fixed
State 11-Closed, duplicate of 4313887, request for enhancement
Priority: 4-Low
Related Bugs 4313887
Submit Date 12-NOV-2003
Description


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) 
======================================================================
Posted Date : 2005-08-25 19:32:52.0
Work Around
N/A
Evaluation
It is not possible to change delete to throw IOException in this case because that would be incompatible. It would be possible to offer some other method that does throw under these circumstances, either in File or some new file handling facility.
  xxxxx@xxxxx   2003-11-12
This feature has been addressed by the new file system API defined by JSR-203. In particular, for a File f then f.toPath().delete() will throw an IOException if the delete fails.
Posted Date : 2009-02-16 13:44:04.0
Comments
  
  Include a link with my name & email   

Submitted On 14-NOV-2003
MartinHilpert
what about File.erase() ?


Submitted On 03-JAN-2004
coxcu
Another problem with always returning a boolean is the
confusion that results if the file didn't exist.  I argue
that an IllegalStateException should be thrown if the file
doesn't exist.


Submitted On 25-NOV-2004
_win32pro
Agree 100% with that. Causes an unbelievable grief!!!


Submitted On 22-AUG-2007
KristianRink
I stumbled across this only a while ago and wonder while, > 2 years later, this is still open. Voted for it. Looking at java.io.File I see most essential methods throwing exceptions given something goes wrong - what kind of considerations keep this from happening with File.delete()?



PLEASE NOTE: JDK6 is formerly known as Project Mustang