classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: FileNotFoundException for opening dirs as files


From: Mark Wielaard
Subject: [cp-patches] FYI: FileNotFoundException for opening dirs as files
Date: Fri, 29 Apr 2005 18:54:27 +0200

Hi,

This is the patch that Jeroen and Dalibor discussed a while ago to fix
the regression with respect to not throwing a FileNotFoundException when
opening a dir as FileInputStream or RandomAccessFile. It has been in
kaffe CVS for more then a month already. All my smoke tests pass. And it
fixes a couple of mauve regressions without introducing new ones.

2005-04-29  Dalibor Topic  <address@hidden>

       * java/nio/channels/FileChannelImpl.java
       (FileChannelImpl(Sting, int)): Removed.
       (FileChannelImpl(File, int)) Added. Check if opened file is a
       directory.

       * java/io/FileInputStream.java(FileInputStream): Fixed javadocs.
       Call FileChannelImpl(File, int).

       * java/io/FileOutputStream.java (FileInputStream): Call
       FileChannelImpl(File, int).

       * java/io/RandomAccessFile.java (RandomAccessFile):
       Call FileChannelImpl(File, int). Switched constructors around.

Checking this in.

Hopefully the last code change before the snapshot release.
Now just checking for other mauve regressions since 0.14 thenupdating
the documentation. Unfortunately it seems the FSF has started moving
servers so you will probably read this on Monday when (hopefully) the
release is already out.

Cheers,

Mark
Index: java/io/FileInputStream.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/FileInputStream.java,v
retrieving revision 1.31
diff -u -r1.31 FileInputStream.java
--- java/io/FileInputStream.java        3 Mar 2005 08:56:02 -0000       1.31
+++ java/io/FileInputStream.java        29 Apr 2005 16:45:16 -0000
@@ -76,7 +76,8 @@
    * @param name The name of the file this stream should read from
    *
    * @exception SecurityException If read access to the file is not allowed
-   * @exception FileNotFoundException If the file does not exist.
+   * @exception FileNotFoundException If the file does not exist 
+   * or if it is a directory
    */
   public FileInputStream(String name) throws FileNotFoundException
   {
@@ -97,7 +98,8 @@
    * @param file The <code>File</code> object this stream should read from
    *
    * @exception SecurityException If read access to the file is not allowed
-   * @exception FileNotFoundException If the file does not exist.
+   * @exception FileNotFoundException If the file does not exist
+   * or if it is a directory.
    */
   public FileInputStream(File file) throws FileNotFoundException
   {
@@ -105,7 +107,7 @@
     if (s != null)
       s.checkRead(file.getPath());
 
-    ch = new FileChannelImpl (file.getPath(), FileChannelImpl.READ);
+    ch = new FileChannelImpl (file, FileChannelImpl.READ);
   }
 
   /**
Index: java/io/FileOutputStream.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/FileOutputStream.java,v
retrieving revision 1.34
diff -u -r1.34 FileOutputStream.java
--- java/io/FileOutputStream.java       3 Mar 2005 08:56:02 -0000       1.34
+++ java/io/FileOutputStream.java       29 Apr 2005 16:45:16 -0000
@@ -155,10 +155,10 @@
     if (s != null)
       s.checkWrite(file.getPath());
 
-    ch = new FileChannelImpl (file.getPath(), (append
-                                    ? FileChannelImpl.WRITE
-                                    | FileChannelImpl.APPEND
-                                    : FileChannelImpl.WRITE));
+   ch = new FileChannelImpl (file, (append
+                                   ? FileChannelImpl.WRITE
+                                   | FileChannelImpl.APPEND
+                                   : FileChannelImpl.WRITE));
   }
 
   /**
Index: java/io/RandomAccessFile.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/RandomAccessFile.java,v
retrieving revision 1.44
diff -u -r1.44 RandomAccessFile.java
--- java/io/RandomAccessFile.java       16 Feb 2005 11:18:37 -0000      1.44
+++ java/io/RandomAccessFile.java       29 Apr 2005 16:45:16 -0000
@@ -86,38 +86,12 @@
    * illegal value
    * @exception SecurityException If the requested access to the file 
    * is not allowed
-   * @exception IOException If any other error occurs
+   * @exception FileNotFoundException If the file is a directory, or 
+   * any other error occurs
    */
   public RandomAccessFile (File file, String mode)
     throws FileNotFoundException
   {
-    this (file.getPath(), mode);
-  }
-
-  /**
-   * This method initializes a new instance of <code>RandomAccessFile</code>
-   * to read from the specified file name with the specified access mode.
-   * The access mode is either "r" for read only access, "rw" for read
-   * write access, "rws" for synchronized read/write access of both
-   * content and metadata, or "rwd" for read/write access
-   * where only content is required to be synchronous.
-   * <p>
-   * Note that a <code>SecurityManager</code> check is made prior to
-   * opening the file to determine whether or not this file is allowed to
-   * be read or written.
-   *
-   * @param fileName The name of the file to read and/or write
-   * @param mode "r", "rw", "rws", or "rwd"
-   *
-   * @exception IllegalArgumentException If <code>mode</code> has an 
-   * illegal value
-   * @exception SecurityException If the requested access to the file 
-   * is not allowed
-   * @exception FileNotFoundException If any other error occurs
-   */
-  public RandomAccessFile (String fileName, String mode)
-    throws FileNotFoundException
-  {
     int fdmode;
     if (mode.equals("r"))
       fdmode = FileChannelImpl.READ;
@@ -136,6 +110,8 @@
     else
       throw new IllegalArgumentException ("invalid mode: " + mode);
 
+    final String fileName = file.getPath();
+
     // The obligatory SecurityManager stuff
     SecurityManager s = System.getSecurityManager();
     if (s != null)
@@ -146,13 +122,41 @@
           s.checkWrite(fileName);
       }
 
-    ch = new FileChannelImpl (fileName, fdmode);
+    ch = new FileChannelImpl (file, fdmode);
     fd = new FileDescriptor(ch);
     out = new DataOutputStream (new FileOutputStream (fd));
     in = new DataInputStream (new FileInputStream (fd));
   }
 
   /**
+   * This method initializes a new instance of <code>RandomAccessFile</code>
+   * to read from the specified file name with the specified access mode.
+   * The access mode is either "r" for read only access, "rw" for read
+   * write access, "rws" for synchronized read/write access of both
+   * content and metadata, or "rwd" for read/write access
+   * where only content is required to be synchronous.
+   * <p>
+   * Note that a <code>SecurityManager</code> check is made prior to
+   * opening the file to determine whether or not this file is allowed to
+   * be read or written.
+   *
+   * @param fileName The name of the file to read and/or write
+   * @param mode "r", "rw", "rws", or "rwd"
+   *
+   * @exception IllegalArgumentException If <code>mode</code> has an 
+   * illegal value
+   * @exception SecurityException If the requested access to the file 
+   * is not allowed
+   * @exception FileNotFoundException If the file is a directory or 
+   * any other error occurs
+   */
+  public RandomAccessFile (String fileName, String mode)
+    throws FileNotFoundException
+  {
+    this (new File(fileName), mode);
+  }
+
+  /**
    * This method closes the file and frees up all file related system
    * resources.  Since most operating systems put a limit on how many files
    * may be opened at any given time, it is a good idea to close all files

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]