Skip to content

Commit 3b6fe46

Browse files
committed
The bug fix for [COMPRESS-714] is better done in Commons IO
1 parent b45611d commit 3b6fe46

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.Map;
3636
import java.util.Objects;
3737

38+
import org.apache.commons.compress.CompressException;
3839
import org.apache.commons.compress.archivers.ArchiveException;
3940
import org.apache.commons.compress.archivers.ArchiveFile;
4041
import org.apache.commons.compress.archivers.zip.ZipEncoding;
@@ -192,13 +193,15 @@ private TarFile(final Builder builder) throws IOException {
192193
entries.add(entry);
193194
}
194195
} catch (final IOException e) {
195-
final ArchiveException ae = new ArchiveException("Error reading Zip content from " + builder, (Throwable) e);
196+
final IOException archiveException = e instanceof CompressException
197+
? (IOException) e
198+
: new ArchiveException("Error reading Zip content from " + builder, (Throwable) e);
196199
try {
197200
this.archive.close();
198201
} catch (final IOException closeException) {
199-
ae.addSuppressed(closeException);
202+
archiveException.addSuppressed(closeException);
200203
}
201-
throw ae;
204+
throw archiveException;
202205
}
203206
}
204207

src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.zip.Inflater;
5050
import java.util.zip.ZipException;
5151

52+
import org.apache.commons.compress.CompressException;
5253
import org.apache.commons.compress.archivers.AbstractArchiveBuilder;
5354
import org.apache.commons.compress.archivers.ArchiveException;
5455
import org.apache.commons.compress.archivers.ArchiveFile;
@@ -755,8 +756,8 @@ private ZipFile(final Builder builder) throws IOException {
755756
resolveLocalFileHeaderData(entriesWithoutUTF8Flag);
756757
}
757758
fillNameMap();
758-
} catch (final IOException | IllegalArgumentException e) {
759-
final IOException archiveException = e instanceof IOException
759+
} catch (final IOException e) {
760+
final IOException archiveException = e instanceof CompressException
760761
? (IOException) e
761762
: new ArchiveException("Error reading Zip content from " + builder.getName(), (Throwable) e);
762763
this.closed = true;

src/test/java/org/apache/commons/compress/archivers/zip/ZipCompress714Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222
import static org.junit.jupiter.api.Assertions.assertThrows;
2323

24-
import java.io.EOFException;
2524
import java.io.IOException;
2625

26+
import org.apache.commons.compress.archivers.ArchiveException;
2727
import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
2828
import org.junit.jupiter.api.Test;
2929

@@ -35,7 +35,7 @@ public class ZipCompress714Test {
3535
@Test
3636
public void testIllegalPosition() throws IOException {
3737
final byte[] data = { 80, 75, 5, 6, -127, 80, 75, 5, 6, 7, -127, -127, -127, 80, 74, 7, 8, -127, -127, -127, -127, -127 };
38-
assertThrows(EOFException.class, () -> ZipFile.builder().setChannel(new SeekableInMemoryByteChannel(data)).get());
39-
assertThrows(EOFException.class, () -> ZipFile.builder().setByteArray(data).get());
38+
assertThrows(ArchiveException.class, () -> ZipFile.builder().setChannel(new SeekableInMemoryByteChannel(data)).get());
39+
assertThrows(ArchiveException.class, () -> ZipFile.builder().setByteArray(data).get());
4040
}
4141
}

0 commit comments

Comments
 (0)