Repository: commons-compress
Updated Branches:
  refs/heads/master 5e108a2e7 -> 19e1b02f7


fix issues detected by Sonar


Project: http://git-wip-us.apache.org/repos/asf/commons-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-compress/commit/9caad351
Tree: http://git-wip-us.apache.org/repos/asf/commons-compress/tree/9caad351
Diff: http://git-wip-us.apache.org/repos/asf/commons-compress/diff/9caad351

Branch: refs/heads/master
Commit: 9caad351f30249cc72fb2840f87ad12fe660978f
Parents: 5e108a2
Author: Stefan Bodewig <bode...@apache.org>
Authored: Sat Jun 24 18:46:06 2017 +0200
Committer: Stefan Bodewig <bode...@apache.org>
Committed: Sat Jun 24 18:46:06 2017 +0200

----------------------------------------------------------------------
 .../archivers/dump/DumpArchiveEntry.java        |  2 +-
 .../compress/archivers/zip/X7875_NewUnix.java   | 32 ++++++++++++++------
 2 files changed, 23 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-compress/blob/9caad351/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntry.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntry.java
 
b/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntry.java
index 47e53ce..c38cfda 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntry.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntry.java
@@ -409,7 +409,7 @@ public class DumpArchiveEntry implements ArchiveEntry {
 
         final DumpArchiveEntry rhs = (DumpArchiveEntry) o;
 
-        if ((header == null) || (rhs.header == null)) {
+        if (rhs.header == null) {
             return false;
         }
 

http://git-wip-us.apache.org/repos/asf/commons-compress/blob/9caad351/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java 
b/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java
index 9e1c01c..a540dba 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/X7875_NewUnix.java
@@ -132,8 +132,10 @@ public class X7875_NewUnix implements ZipExtraField, 
Cloneable, Serializable {
      */
     @Override
     public ZipShort getLocalFileDataLength() {
-        final int uidSize = 
trimLeadingZeroesForceMinLength(uid.toByteArray()).length;
-        final int gidSize = 
trimLeadingZeroesForceMinLength(gid.toByteArray()).length;
+        byte[] b = trimLeadingZeroesForceMinLength(uid.toByteArray());
+        final int uidSize = b == null ? 0 : b.length;
+        b = trimLeadingZeroesForceMinLength(gid.toByteArray());
+        final int gidSize = b == null ? 0 : b.length;
 
         // The 3 comes from:  version=1 + uidsize=1 + gidsize=1
         return new ZipShort(3 + uidSize + gidSize);
@@ -165,26 +167,36 @@ public class X7875_NewUnix implements ZipExtraField, 
Cloneable, Serializable {
         // (e.g., so that the sign-bit is set to zero).  We need to remove that
         // before sending the number over the wire.
         uidBytes = trimLeadingZeroesForceMinLength(uidBytes);
+        int uidBytesLen = uidBytes != null ? uidBytes.length : 0;
         gidBytes = trimLeadingZeroesForceMinLength(gidBytes);
+        int gidBytesLen = gidBytes != null ? gidBytes.length : 0;
 
         // Couldn't bring myself to just call getLocalFileDataLength() when 
we've
         // already got the arrays right here.  Yeah, yeah, I know, premature
         // optimization is the root of all...
         //
         // The 3 comes from:  version=1 + uidsize=1 + gidsize=1
-        final byte[] data = new byte[3 + uidBytes.length + gidBytes.length];
+        final byte[] data = new byte[3 + uidBytesLen + gidBytesLen];
 
         // reverse() switches byte array from big-endian to little-endian.
-        reverse(uidBytes);
-        reverse(gidBytes);
+        if (uidBytes != null) {
+            reverse(uidBytes);
+        }
+        if (gidBytes != null) {
+            reverse(gidBytes);
+        }
 
         int pos = 0;
         data[pos++] = unsignedIntToSignedByte(version);
-        data[pos++] = unsignedIntToSignedByte(uidBytes.length);
-        System.arraycopy(uidBytes, 0, data, pos, uidBytes.length);
-        pos += uidBytes.length;
-        data[pos++] = unsignedIntToSignedByte(gidBytes.length);
-        System.arraycopy(gidBytes, 0, data, pos, gidBytes.length);
+        data[pos++] = unsignedIntToSignedByte(uidBytesLen);
+        if (uidBytes != null) {
+            System.arraycopy(uidBytes, 0, data, pos, uidBytesLen);
+        }
+        pos += uidBytesLen;
+        data[pos++] = unsignedIntToSignedByte(gidBytesLen);
+        if (gidBytes != null) {
+            System.arraycopy(gidBytes, 0, data, pos, gidBytesLen);
+        }
         return data;
     }
 

Reply via email to