We are throwing a FileNotFoundException when trying to open a ZipFile
that doesn't exist. However, we should throw a ZipException instead.
This patch fixes this.

2006-03-16  Roman Kennke  <[EMAIL PROTECTED]>

        * java/util/zip/ZipFile.java
        (openFile): New helper method.
        (ZipFile): Use new openFile method to ensure the proper
        exception is thrown. This applies for all overloaded
constructors.

/Roman

-- 
“Improvement makes straight roads, but the crooked roads, without
Improvement, are roads of Genius.” - William Blake
Index: java/util/zip/ZipFile.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/zip/ZipFile.java,v
retrieving revision 1.29
diff -u -r1.29 ZipFile.java
--- java/util/zip/ZipFile.java	16 Mar 2006 01:20:17 -0000	1.29
+++ java/util/zip/ZipFile.java	16 Mar 2006 14:29:42 -0000
@@ -43,6 +43,7 @@
 
 import java.io.EOFException;
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.RandomAccessFile;
@@ -91,6 +92,37 @@
 
   private boolean closed = false;
 
+
+  /**
+   * Helper function to open RandomAccessFile and throw the proper
+   * ZipException in case opening the file fails.
+   *
+   * @param name the file name, or null if file is provided
+   *
+   * @param file the file, or null if name is provided
+   *
+   * @return the newly open RandomAccessFile, never null
+   */
+  private RandomAccessFile openFile(String name, 
+                                    File file) 
+    throws ZipException, IOException
+  {                                       
+    try 
+      {
+        return 
+          (name != null)
+          ? new RandomAccessFile(name, "r")
+          : new RandomAccessFile(file, "r");
+      }
+    catch (FileNotFoundException f)
+      { 
+        ZipException ze = new ZipException(f.getMessage());
+        ze.initCause(f);
+        throw ze;
+      }
+  }
+
+
   /**
    * Opens a Zip file with the given name for reading.
    * @exception IOException if a i/o error occured.
@@ -99,7 +131,7 @@
    */
   public ZipFile(String name) throws ZipException, IOException
   {
-    this.raf = new RandomAccessFile(name, "r");
+    this.raf = openFile(name,null);
     this.name = name;
     checkZipFile();
   }
@@ -112,7 +144,7 @@
    */
   public ZipFile(File file) throws ZipException, IOException
   {
-    this.raf = new RandomAccessFile(file, "r");
+    this.raf = openFile(null,file);
     this.name = file.getPath();
     checkZipFile();
   }
@@ -139,7 +171,7 @@
       throw new IllegalArgumentException("invalid mode");
     if ((mode & OPEN_DELETE) != 0)
       file.deleteOnExit();
-    this.raf = new RandomAccessFile(file, "r");
+    this.raf = openFile(null,file);
     this.name = file.getPath();
     checkZipFile();
   }

Reply via email to