Kevin Zhou wrote:
The FileNotFoundException is being thrown by the constructor of
FileOutputStream when that constructor is attempting to open File f for
writing and it doesn't have permission to do so.

To open f the FileOutputStream class is calling
org.apache.harmony.luni.platform.OSFileSystem.open(). The
o.a.h.l.p.OSFileSystem.open() method invokes a native openImpl() method. The
native method can fail for several reasons. The problem lies in the fact
that the reason behind the failure of the native method isn't being
propagated back to the FileOutputStream which is creating the
FileNotFoundException upon failure.
Yes, the native code just return -1 to indicate an error occurred, while in hyfile.c::hyfile_open, error messages are set by portLibrary->error_set_last_error, but the caller never use them. So I suggest to add a method in OSFileSystem.c to retrieve the error messages. The java could get the failure reasons when the native return -1, and add them to the exception message.

On Fri, Dec 5, 2008 at 10:50 AM, Kevin Zhou (JIRA) <[EMAIL PROTECTED]> wrote:

[classlib] [luni] Should Improve File System Exception Messages
---------------------------------------------------------------

                Key: HARMONY-6034
                URL: https://issues.apache.org/jira/browse/HARMONY-6034
            Project: Harmony
         Issue Type: Improvement
         Components: Classlib
   Affects Versions: 5.0M8
           Reporter: Kevin Zhou
            Fix For: 5.0M9


Given a test scenario [1] where "t:" is a mapped drive letter to which the
current user only has R+E access but doesn't have W acess.
Conduct this on RI [2] and HARMONY [3]. Obviously, RI return a
FileNotFoundException with a "Access is denied" message while HARMONY does
not provide information as to why the file is not found. This also occurs
when the corresponding file doesn't exist, RI will throw FNF with "system
fails to find ...".

I think there is a difference in information returned that makes it a bit
easier to understand why the FNF Exception is occurring.
Should we improve this?

[1]
   public static void main(String[] args) {
       try {
           File f = new File("t:/temp.file");
           if (f.exists()) {
               System.out.println("File " + f.getAbsolutePath() + "
exists");
           }
           FileOutputStream fos = new FileOutputStream(f);
           fos.write("Hello, World!".getBytes());
           fos.close();
       } catch (FileNotFoundException fnfe) {
           fnfe.printStackTrace(System.err);
       } catch (Throwable t) {
           t.printStackTrace(System.err);
       }
   }

[2] Output from a FileNotFoundException on RI:
java.io.FileNotFoundException: t:/temp.file (Access is denied)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(FileOutputStream.java:201)
at java.io.FileOutputStream.<init>(FileOutputStream.java:153)
at test.Main.main(Main.java:23)

[3] Output from a FileNotFoundException on HARMONY:
java.io.FileNotFoundException: t:/temp.file
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at test.Main.main(Main.java:23)

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.



Reply via email to