You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/06/16 17:55:24 UTC

[commons-compress] branch master updated: Use try-with-resources (#391)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


The following commit(s) were added to refs/heads/master by this push:
     new 21e674c4 Use try-with-resources (#391)
21e674c4 is described below

commit 21e674c44ae5844399e964b14c0c925e62f84a25
Author: Daniele Galloppo <81...@users.noreply.github.com>
AuthorDate: Fri Jun 16 19:55:18 2023 +0200

    Use try-with-resources (#391)
---
 .../org/apache/commons/compress/archivers/ArchiveStreamFactory.java | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
index 22f9b088..f718870b 100644
--- a/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
+++ b/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
@@ -264,9 +264,7 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
 
         // COMPRESS-117 - improve auto-recognition
         if (signatureLength >= TAR_HEADER_SIZE) {
-            TarArchiveInputStream tais = null;
-            try {
-                tais = new TarArchiveInputStream(new ByteArrayInputStream(tarHeader));
+            try (TarArchiveInputStream tais = new TarArchiveInputStream(new ByteArrayInputStream(tarHeader))) {
                 // COMPRESS-191 - verify the header checksum
                 if (tais.getNextTarEntry().isCheckSumOK()) {
                     return TAR;
@@ -276,8 +274,6 @@ public class ArchiveStreamFactory implements ArchiveStreamProvider {
                 // as IOException
                 // autodetection, simply not a TAR
                 // ignored
-            } finally {
-                IOUtils.closeQuietly(tais);
             }
         }
         throw new ArchiveException("No Archiver found for the stream signature");