Skip to content

Commit cab216b

Browse files
committed
Use IOUtils.close[Quietly]()
1 parent 0cfaec9 commit cab216b

File tree

6 files changed

+11
-18
lines changed

6 files changed

+11
-18
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ Brotli, Zstandard and ar, cpio, jar, tar, zip, dump, 7z, arj.
207207
<dependency>
208208
<groupId>commons-io</groupId>
209209
<artifactId>commons-io</artifactId>
210-
<version>2.21.1-SNAPSHOT</version>
210+
<version>2.22.0-SNAPSHOT</version>
211211
</dependency>
212212
<dependency>
213213
<groupId>org.apache.commons</groupId>

src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,7 @@ private SevenZFile(final Builder builder) throws IOException {
629629
archive = readHeaders(password);
630630
this.password = password != null ? Arrays.copyOf(password, password.length) : null;
631631
} catch (final ArithmeticException | IllegalArgumentException e) {
632-
final ArchiveException archiveException = new ArchiveException(e);
633-
IOUtils.close(channel, archiveException::addSuppressed);
634-
throw archiveException;
632+
throw IOUtils.closeQuietly(channel, new ArchiveException(e));
635633
}
636634
}
637635

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,8 @@ private TarFile(final Builder builder) throws IOException {
192192
while ((entry = getNextTarEntry()) != null) {
193193
entries.add(entry);
194194
}
195-
} catch (final IOException ex) {
196-
IOUtils.close(archive, ex::addSuppressed);
197-
throw ex;
195+
} catch (final IOException e) {
196+
throw IOUtils.closeQuietly(archive, e);
198197
}
199198
}
200199

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -756,12 +756,8 @@ private ZipFile(final Builder builder) throws IOException {
756756
}
757757
fillNameMap();
758758
} catch (final IOException e) {
759-
final ArchiveException archiveException = e instanceof ArchiveException
760-
? (ArchiveException) e
761-
: new ArchiveException("Error reading Zip content from " + builder.getName(), (Throwable) e);
762759
this.closed = true;
763-
IOUtils.close(archive, archiveException::addSuppressed);
764-
throw archiveException;
760+
throw IOUtils.closeQuietly(archive, e);
765761
}
766762
}
767763

src/test/java/org/apache/commons/compress/archivers/tar/TarCompress714Test.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;
2425
import java.io.IOException;
2526

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

@@ -48,7 +48,7 @@ public void testIllegalPosition() throws IOException {
4848
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -65,
4949
-1, -126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -128, -1, -1, -1, -1, 0, -122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -128, 0, 0, 0, 0, 35, 0, 53, 0, 0, 0,
5050
0, 0, 0, 32, 56, 0, 0, 0, 0, 0, 0, 0 };
51-
assertThrows(ArchiveException.class, () -> TarFile.builder().setChannel(new SeekableInMemoryByteChannel(data)).get());
52-
assertThrows(ArchiveException.class, () -> TarFile.builder().setByteArray(data).get());
51+
assertThrows(EOFException.class, () -> TarFile.builder().setChannel(new SeekableInMemoryByteChannel(data)).get());
52+
assertThrows(EOFException.class, () -> TarFile.builder().setByteArray(data).get());
5353
}
5454
}

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;
2425
import java.io.IOException;
2526

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(ArchiveException.class, () -> ZipFile.builder().setChannel(new SeekableInMemoryByteChannel(data)).get());
39-
assertThrows(ArchiveException.class, () -> ZipFile.builder().setByteArray(data).get());
38+
assertThrows(EOFException.class, () -> ZipFile.builder().setChannel(new SeekableInMemoryByteChannel(data)).get());
39+
assertThrows(EOFException.class, () -> ZipFile.builder().setByteArray(data).get());
4040
}
4141
}

0 commit comments

Comments
 (0)