You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2020/01/23 17:57:16 UTC

[commons-compress] branch master updated: make Sonar a bit less unhappy

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

bodewig 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 f18f449  make Sonar a bit less unhappy
f18f449 is described below

commit f18f44936b4dc7002e21423c4c533b132bade9af
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Thu Jan 23 18:56:54 2020 +0100

    make Sonar a bit less unhappy
---
 .../org/apache/commons/compress/archivers/sevenz/SevenZFile.java  | 2 +-
 .../commons/compress/archivers/tar/TarArchiveInputStream.java     | 3 ++-
 .../commons/compress/archivers/zip/ZipArchiveOutputStream.java    | 8 ++++----
 .../commons/compress/archivers/zip/ZipSplitOutputStream.java      | 6 ++----
 .../compress/compressors/pack200/TempFileCachingStreamBridge.java | 3 ++-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
index 0e7f0ec..9838c79 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
@@ -471,7 +471,7 @@ public class SevenZFile implements Closeable {
 
     private Archive tryToLocateEndHeader(final byte[] password) throws IOException {
         ByteBuffer nidBuf = ByteBuffer.allocate(1);
-        final long searchLimit = 1024 * 1024 * 1;
+        final long searchLimit = 1024l * 1024 * 1;
         // Main header, plus bytes that readStartHeader would read
         final long previousDataSize = channel.position() + 20;
         final long minPos;
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index 920c8fd..e27b490 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -1059,7 +1059,8 @@ public class TarArchiveInputStream extends ArchiveInputStream {
         }
 
         if (sparseHeaders != null) {
-            final InputStream zeroInputStream = new TarArchiveSparseZeroInputStream();
+            // Stream doesn't need to be closed at all as it doesn't use any resources
+            final InputStream zeroInputStream = new TarArchiveSparseZeroInputStream(); //NOSONAR
             long offset = 0;
             for (TarArchiveStructSparse sparseHeader : sparseHeaders) {
                 if (sparseHeader.getOffset() == 0 && sparseHeader.getNumbytes() == 0) {
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
index 9df786a..f899895 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
@@ -536,7 +536,7 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream {
 
         // calculate the length of end of central directory, as it may be used in writeZip64CentralDirectory
         final ByteBuffer commentData = this.zipEncoding.encode(comment);
-        final int commentLength = commentData.limit() - commentData.position();
+        final long commentLength = commentData.limit() - commentData.position();
         eocdLength = WORD /* length of EOCD_SIG */
                 + SHORT /* number of this disk */
                 + SHORT /* disk number of start of central directory */
@@ -1637,12 +1637,12 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream {
         if(isSplitZip) {
             // based on the zip specification, the End Of Central Directory record and
             // the Zip64 End Of Central Directory locator record must be on the same segment
-            long zip64EOCDLOCLength = WORD  /* length of ZIP64_EOCD_LOC_SIG */
+            final int zip64EOCDLOCLength = WORD  /* length of ZIP64_EOCD_LOC_SIG */
                     + WORD  /* disk number of ZIP64_EOCD_SIG */
                     + DWORD /* offset of ZIP64_EOCD_SIG */
                     + WORD  /* total number of disks */;
 
-            long unsplittableContentSize = zip64EOCDLOCLength + eocdLength;
+            final long unsplittableContentSize = zip64EOCDLOCLength + eocdLength;
             ((ZipSplitOutputStream)this.out).prepareToWriteUnsplittableContent(unsplittableContentSize);
         }
 
@@ -1657,7 +1657,7 @@ public class ZipArchiveOutputStream extends ArchiveOutputStream {
         if(isSplitZip) {
             // the Zip64 End Of Central Directory Locator and the End Of Central Directory must be
             // in the same split disk, it means they must be located in the last disk
-            long totalNumberOfDisks = ((ZipSplitOutputStream)this.out).getCurrentSplitSegmentIndex() + 1;
+            final int totalNumberOfDisks = ((ZipSplitOutputStream)this.out).getCurrentSplitSegmentIndex() + 1;
             writeOut(ZipLong.getBytes(totalNumberOfDisks));
         } else {
             writeOut(ONE);
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java
index 0a84053..7f62646 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipSplitOutputStream.java
@@ -176,15 +176,13 @@ class ZipSplitOutputStream extends OutputStream {
 
         newFile = createNewSplitSegmentFile(null);
 
-
-        OutputStream newFileOutputStream = new FileOutputStream(newFile);
         outputStream.close();
-        outputStream = newFileOutputStream;
+        outputStream = new FileOutputStream(newFile);
         currentSplitSegmentBytesWritten = 0;
         zipFile = newFile;
         currentSplitSegmentIndex++;
 
-        return newFileOutputStream;
+        return outputStream;
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/compress/compressors/pack200/TempFileCachingStreamBridge.java b/src/main/java/org/apache/commons/compress/compressors/pack200/TempFileCachingStreamBridge.java
index 5403eed..57390d8 100644
--- a/src/main/java/org/apache/commons/compress/compressors/pack200/TempFileCachingStreamBridge.java
+++ b/src/main/java/org/apache/commons/compress/compressors/pack200/TempFileCachingStreamBridge.java
@@ -48,7 +48,8 @@ class TempFileCachingStreamBridge extends StreamBridge {
                 try {
                     super.close();
                 } finally {
-                    f.delete();
+                    // if this fails the only thing we can do is to rely on deleteOnExit
+                    f.delete(); // NOSONAR
                 }
             }
         };