JDK-4079140 : IOException should have subclasses to better describe failure
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.1,1.1.3,1.1.4,1.1.6
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic,solaris_2.5.1,windows_nt
  • CPU: generic,x86,sparc
  • Submitted: 1997-09-15
  • Updated: 2017-07-20
  • Resolved: 2017-07-20
Related Reports
Duplicate :  
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description
Name: tb29552			Date: 09/15/97


 Trying to write to a write-protected file yields 
 a FileNotFound exception. Looking at the source
 code, we see that an IOException is being caught
 and re-thrown as a FileNotFoundException.

 Therefore, we are losing the actual error (file
 can't be read) and gaining a bogus error (file can't
 be found). Since the original exception is lost,
 we don't know (without further work) whether the
 file doesn't exist or is just not writable.

 excerpting out of FileOutputStream.java <colon>

    public FileInputStream(String name) throws FileNotFoundException {
        SecurityManager security = System.getSecurityManager();
        if (security != null) {
            security.checkRead(name);
        }
        try {
            fd = new FileDescriptor();
            open(name);
        } catch (IOException e) {
            throw new FileNotFoundException(name);
        }
    }

 company - Integrated Measurement Systems , email - ###@###.###
======================================================================

Comments
In general, it's only useful to have different exception types if the caller is expected to behave differently in response. Nio has added some specific exception types for specific cases. But we aren't going to go through java.io and rearrange exception types simply to provide finer-grained detail. In the submitter's case, the problem might be that the original exception is thrown away; this kind of issue has been mitigated through the exception chaining mechanism. If there are specific cases where exceptions aren't chained but should be, bugs should be filed separately for them. Closing as Won't Fix.
20-07-2017

WORK AROUND Name: tb29552 Date: 09/15/97 ======================================================================
11-06-2004

EVALUATION Not a bug. The FileOutputStream constructors are intended only to throw FileNotFoundException. It would be reasonable, however, to have subclasses of this exception to indicate conditions such as a read-only file, so I've converted this bug report into an RFE. -- mr@eng 1997/11/3 More generally, we should expand the IOException hierarchy to report error conditionsn in much more detail. -- mr@eng 1998/11/16 java.nio has provided a richer set of exceptions for error conditions. ###@###.### 2002-05-07
11-06-0182