avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bus...@apache.org
Subject avro git commit: AVRO-1982: Fix static code analyzer findings. Contributed by Zoltan Ivanfi.
Date Fri, 27 Jan 2017 22:40:24 GMT
Repository: avro
Updated Branches:
  refs/heads/master f8c70a3a9 -> 6bdc8f43e


AVRO-1982: Fix static code analyzer findings. Contributed by Zoltan Ivanfi.

Fixed several possible null pointer exceptions and unchecked casts.
These triggered security and code health warnings in our static code
analyzer tools.

Closes #173.

Signed-off-by: Gabor Szadovszky <gabor.szadovszky@cloudera.com>
Signed-off-by: Sean Busbey <busbey@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/avro/repo
Commit: http://git-wip-us.apache.org/repos/asf/avro/commit/6bdc8f43
Tree: http://git-wip-us.apache.org/repos/asf/avro/tree/6bdc8f43
Diff: http://git-wip-us.apache.org/repos/asf/avro/diff/6bdc8f43

Branch: refs/heads/master
Commit: 6bdc8f43e1ac2019e5a405c3edb4cf8fb795ccf8
Parents: f8c70a3
Author: Zoltan Ivanfi <zi@cloudera.com>
Authored: Mon Dec 19 18:27:45 2016 +0100
Committer: Sean Busbey <busbey@apache.org>
Committed: Fri Jan 27 11:14:15 2017 -0600

----------------------------------------------------------------------
 lang/java/avro/src/main/java/org/apache/avro/Schema.java       | 3 +++
 .../avro/src/main/java/org/apache/avro/file/BZip2Codec.java    | 2 +-
 .../avro/src/main/java/org/apache/avro/file/DeflateCodec.java  | 2 +-
 .../avro/src/main/java/org/apache/avro/file/NullCodec.java     | 2 +-
 .../avro/src/main/java/org/apache/avro/file/SnappyCodec.java   | 2 +-
 lang/java/avro/src/main/java/org/apache/avro/file/XZCodec.java | 2 +-
 .../main/java/org/apache/avro/util/WeakIdentityHashMap.java    | 6 ++++++
 7 files changed, 14 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/avro/blob/6bdc8f43/lang/java/avro/src/main/java/org/apache/avro/Schema.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/Schema.java b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
index 2019c1f..53e5e2e 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/Schema.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/Schema.java
@@ -464,6 +464,8 @@ public abstract class Schema extends JsonProperties {
     private boolean defaultValueEquals(JsonNode thatDefaultValue) {
       if (defaultValue == null)
         return thatDefaultValue == null;
+      if (thatDefaultValue == null)
+        return false;
       if (Double.isNaN(defaultValue.getDoubleValue()))
         return Double.isNaN(thatDefaultValue.getDoubleValue());
       return defaultValue.equals(thatDefaultValue);
@@ -587,6 +589,7 @@ public abstract class Schema extends JsonProperties {
     private Object s1; private Object s2;
     private SeenPair(Object s1, Object s2) { this.s1 = s1; this.s2 = s2; }
     public boolean equals(Object o) {
+      if (!(o instanceof SeenPair)) return false;
       return this.s1 == ((SeenPair)o).s1 && this.s2 == ((SeenPair)o).s2;
     }
     public int hashCode() {

http://git-wip-us.apache.org/repos/asf/avro/blob/6bdc8f43/lang/java/avro/src/main/java/org/apache/avro/file/BZip2Codec.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/BZip2Codec.java b/lang/java/avro/src/main/java/org/apache/avro/file/BZip2Codec.java
index 8dccfc3..ca90d6e 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/BZip2Codec.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/BZip2Codec.java
@@ -87,7 +87,7 @@ public class BZip2Codec extends Codec {
   public boolean equals(Object obj) {
     if (this == obj)
       return true;
-    if (getClass() != obj.getClass())
+    if (obj == null || obj.getClass() != getClass())
       return false;
     return true;
   }

http://git-wip-us.apache.org/repos/asf/avro/blob/6bdc8f43/lang/java/avro/src/main/java/org/apache/avro/file/DeflateCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/DeflateCodec.java b/lang/java/avro/src/main/java/org/apache/avro/file/DeflateCodec.java
index f8f6ac4..bfe9e6d 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/DeflateCodec.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/DeflateCodec.java
@@ -132,7 +132,7 @@ class DeflateCodec extends Codec {
   public boolean equals(Object obj) {
     if (this == obj)
       return true;
-    if (getClass() != obj.getClass())
+    if (obj == null || obj.getClass() != getClass())
       return false;
     DeflateCodec other = (DeflateCodec)obj;
     return (this.nowrap == other.nowrap);

http://git-wip-us.apache.org/repos/asf/avro/blob/6bdc8f43/lang/java/avro/src/main/java/org/apache/avro/file/NullCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/NullCodec.java b/lang/java/avro/src/main/java/org/apache/avro/file/NullCodec.java
index e95f699..bc07f14 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/NullCodec.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/NullCodec.java
@@ -54,7 +54,7 @@ final class NullCodec extends Codec {
   public boolean equals(Object other) {
     if (this == other)
       return true;
-    return (this.getClass() == other.getClass());
+    return (other != null && other.getClass() == getClass());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/avro/blob/6bdc8f43/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java b/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
index 1a5d252..6206c8d 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/SnappyCodec.java
@@ -75,7 +75,7 @@ class SnappyCodec extends Codec {
   public boolean equals(Object obj) {
     if (this == obj)
       return true;
-    if (getClass() != obj.getClass())
+    if (obj == null || obj.getClass() != getClass())
       return false;
     return true;
   }

http://git-wip-us.apache.org/repos/asf/avro/blob/6bdc8f43/lang/java/avro/src/main/java/org/apache/avro/file/XZCodec.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/file/XZCodec.java b/lang/java/avro/src/main/java/org/apache/avro/file/XZCodec.java
index 7677b3f..23aa830 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/file/XZCodec.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/file/XZCodec.java
@@ -109,7 +109,7 @@ public class XZCodec extends Codec {
   public boolean equals(Object obj) {
     if (this == obj)
       return true;
-    if (getClass() != obj.getClass())
+    if (obj == null || obj.getClass() != getClass())
       return false;
     XZCodec other = (XZCodec)obj;
     return (this.compressionLevel == other.compressionLevel);

http://git-wip-us.apache.org/repos/asf/avro/blob/6bdc8f43/lang/java/avro/src/main/java/org/apache/avro/util/WeakIdentityHashMap.java
----------------------------------------------------------------------
diff --git a/lang/java/avro/src/main/java/org/apache/avro/util/WeakIdentityHashMap.java b/lang/java/avro/src/main/java/org/apache/avro/util/WeakIdentityHashMap.java
index a22708a..6958798 100644
--- a/lang/java/avro/src/main/java/org/apache/avro/util/WeakIdentityHashMap.java
+++ b/lang/java/avro/src/main/java/org/apache/avro/util/WeakIdentityHashMap.java
@@ -96,6 +96,9 @@ public class WeakIdentityHashMap<K, V> implements Map<K, V>
{
   }
 
   public boolean equals(Object o) {
+    if (!(o instanceof WeakIdentityHashMap)) {
+      return false;
+    }
     return backingStore.equals(((WeakIdentityHashMap)o).backingStore);
   }
 
@@ -159,6 +162,9 @@ public class WeakIdentityHashMap<K, V> implements Map<K, V>
{
       if (this == o) {
         return true;
       }
+      if (!(o instanceof WeakIdentityHashMap.IdentityWeakReference)) {
+        return false;
+      }
       IdentityWeakReference ref = (IdentityWeakReference)o;
       if (this.get() == ref.get()) {
         return true;


Mime
View raw message