Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8062754

(zipfs) newFileSystem should throw IOException instead of java.util.zip.ZipError

    XMLWordPrintable

Details

    • b48

    Description


      J2SE Version (please include all output from java -version flag):
      Java 7 to Java 9


      Does this problem occur on J2SE 6ux or 7ux? Yes / No (pick one)
      Yes, it occur on Java 7.


      Operating System Configuration Information (be specific):
      Different OS (Windows, Linux)

      Hardware Configuration Information (be specific):
      Different systems


      Bug Description:
      FileSystems.newFileSystem throws a java.util.zip.ZipError on a corrupt zip
      file. This is not documented and a very bad thing. A normal program will not
      handle a java.lang.Error. A better exception will be an IOException or any
      other that extends form java.lang.Exception.

      Steps to Reproduce (be specific):
      Run the follow program (attached)
      import java.io.BufferedWriter;
      import java.io.File;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.OutputStreamWriter;
      import java.net.URI;
      import java.nio.file.FileSystem;
      import java.nio.file.FileSystems;
      import java.nio.file.Paths;
      import java.util.Arrays;
      import java.util.HashMap;
      import java.util.Map;

      public class TestZipFileSystem {

      public static void main( String[] args ) throws IOException,
      InterruptedException {
      File dir = new File( "testdir" );
      dir.mkdir();
      File zipFile = new File( dir, "txtddd.zip" );

      createCorruptFile( zipFile );
      System.out.println( "delete: expected: true was: " + zipFile.delete() );
      System.out.println( "exists: expected: false was: " + zipFile.exists() );
      System.out.println( "list: expected: [] was: " + Arrays.toString( dir.list()
      ) );

      createCorruptFile( zipFile );
      Map<String, String> env = new HashMap<>();
      env.put( "create", "false" );
      URI uri = URI.create( "jar:file:" + Paths.get( zipFile.getAbsolutePath()
      ).toUri().getRawPath() );

      try (FileSystem fs = FileSystems.newFileSystem( uri, env, null )) {
      System.out.println( "newFileSystem: expected: INVALID was: VALID" );
      } catch( Throwable ex ) {
      System.out.println( "newFileSystem: expected: INVALID was: INVALID" );
      System.out.println( "exception: expected: java.io.IOException was: " +
      ex.getClass().getName() );

      System.out.println( "delete: expected: true was: " + zipFile.delete() );
      System.out.println( "exists: expected: false was: " + zipFile.exists() );
      //now not empty, although file is deleted
      System.out.println( "list: expected: [] was: " + Arrays.toString( dir.list()
      ) );


      private static void createCorruptFile( File filePath ) throws IOException {
      BufferedWriter out = null;
      try {
      OutputStreamWriter outputStreamWriter = new OutputStreamWriter( new
      FileOutputStream( filePath ) );
      out = new BufferedWriter( outputStreamWriter );
      out.write( "content stuff\n" );
      } finally {
      if( out != null ) {
      out.close();






      Attachments

        Activity

          People

            sherman Xueming Shen
            shadowbug Shadow Bug
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: