From f3201aeeb06aae3b11e8cf6ee9693182dd896b32 Mon Sep 17 00:00:00 2001 From: Dongjoon Hyun Date: Wed, 9 Mar 2016 10:12:23 +0000 Subject: [SPARK-13692][CORE][SQL] Fix trivial Coverity/Checkstyle defects ## What changes were proposed in this pull request? This issue fixes the following potential bugs and Java coding style detected by Coverity and Checkstyle. - Implement both null and type checking in equals functions. - Fix wrong type casting logic in SimpleJavaBean2.equals. - Add `implement Cloneable` to `UTF8String` and `SortedIterator`. - Remove dereferencing before null check in `AbstractBytesToBytesMapSuite`. - Fix coding style: Add '{}' to single `for` statement in mllib examples. - Remove unused imports in `ColumnarBatch` and `JavaKinesisStreamSuite`. - Remove unused fields in `ChunkFetchIntegrationSuite`. - Add `stop()` to prevent resource leak. Please note that the last two checkstyle errors exist on newly added commits after [SPARK-13583](https://issues.apache.org/jira/browse/SPARK-13583). ## How was this patch tested? manual via `./dev/lint-java` and Coverity site. Author: Dongjoon Hyun Closes #11530 from dongjoon-hyun/SPARK-13692. --- .../org/apache/spark/sql/execution/vectorized/ColumnarBatch.java | 1 - .../src/test/java/test/org/apache/spark/sql/JavaDatasetSuite.java | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'sql') diff --git a/sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/ColumnarBatch.java b/sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/ColumnarBatch.java index 18763672c6..9a8aedfa56 100644 --- a/sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/ColumnarBatch.java +++ b/sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/ColumnarBatch.java @@ -22,7 +22,6 @@ import java.util.Iterator; import org.apache.commons.lang.NotImplementedException; import org.apache.spark.memory.MemoryMode; -import org.apache.spark.sql.Column; import org.apache.spark.sql.catalyst.InternalRow; import org.apache.spark.sql.catalyst.expressions.GenericMutableRow; import org.apache.spark.sql.catalyst.expressions.UnsafeRow; diff --git a/sql/core/src/test/java/test/org/apache/spark/sql/JavaDatasetSuite.java b/sql/core/src/test/java/test/org/apache/spark/sql/JavaDatasetSuite.java index e0e56f3fbf..9b624f318c 100644 --- a/sql/core/src/test/java/test/org/apache/spark/sql/JavaDatasetSuite.java +++ b/sql/core/src/test/java/test/org/apache/spark/sql/JavaDatasetSuite.java @@ -465,6 +465,9 @@ public class JavaDatasetSuite implements Serializable { @Override public boolean equals(Object other) { + if (this == other) return true; + if (other == null || getClass() != other.getClass()) return false; + return this.value.equals(((KryoSerializable) other).value); } @@ -483,6 +486,9 @@ public class JavaDatasetSuite implements Serializable { @Override public boolean equals(Object other) { + if (this == other) return true; + if (other == null || getClass() != other.getClass()) return false; + return this.value.equals(((JavaSerializable) other).value); } @@ -631,7 +637,7 @@ public class JavaDatasetSuite implements Serializable { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - SimpleJavaBean that = (SimpleJavaBean) o; + SimpleJavaBean2 that = (SimpleJavaBean2) o; if (!a.equals(that.a)) return false; if (!b.equals(that.b)) return false; -- cgit v1.2.3