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();