yiang li created COMPRESS-496: --------------------------------- Summary: SevenZFile.read got an exception when extracting empty file Key: COMPRESS-496 URL: https://issues.apache.org/jira/browse/COMPRESS-496 Project: Commons Compress Issue Type: Bug Reporter: yiang li
{color:#FF0000}{color}When extracting an empty file in SevenZFile, an exception will be thrown. This is because the `deferredBlockStreams` in SevenZFile was clear here ``` if (folderIndex < 0) { deferredBlockStreams.clear(); // TODO: previously it'd return an empty stream? // new BoundedInputStream(new ByteArrayInputStream(new byte[0]), 0); return; } ``` Maybe an empty stream should be added to deferredBlockStreams here as the TODO said? Code to reproduce the exception ``` byte[] buffer = new byte[4096]; String destination = "/output/dir/of/7z"; SevenZFile sevenZFile = new SevenZFile(new File("/file/to/extract.7z")); SevenZArchiveEntry entry; while ((entry = sevenZFile.getNextEntry()) != null){ if (entry.isDirectory()){ continue; } File curfile = new File(destination, entry.getName()); File parent = curfile.getParentFile(); if (!parent.exists()) { parent.mkdirs(); } FileOutputStream out = new FileOutputStream(curfile); while(sevenZFile.read(buffer, 0, buffer.length) > 0) { out.write(buffer); out.close(); } } ``` -- This message was sent by Atlassian Jira (v8.3.4#803005)