Fixes for Coverity Issues
(https://scan.coverity.com/projects/hyracks)
- CID 68257 (#1 of 1): Resource leak (RESOURCE_LEAK)
5. leaked_resource: Variable outputStream going out of scope leaks the
resource it refers to.
- CID 68260 (#1 of 1): Useless call (USELESS_CALL)
side_effect_free: Calling equivalentVars.get(0) is only useful for its
return value, which is ignored.
- CID 68261 (#1 of 1): BC: Bad casts of object references
(FB.BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS)
1. defect: Equals method for org.apache.hyracks.algebricks.core.
algebra.properties.LocalOrderProperty assumes the argument is of type
LocalOrderProperty.
- CID 68262 (#1 of 1): BC: Bad casts of object references
(FB.BC_EQUALS_METHOD_SHOULD_WORK_FOR_ALL_OBJECTS)
1. defect: Equals method for org.apache.hyracks.storage.am.rtree.
RTreeCheckTuple assumes the argument is of type RTreeCheckTuple.
Change-Id: I8ba6e578f173b1081a8f55b228704744f08588df
Reviewed-on: https://asterix-gerrit.ics.uci.edu/658
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
Reviewed-by: Till Westmann <tillw@apache.org>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
diff --git a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/LocalOrderProperty.java b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/LocalOrderProperty.java
index d1d0ca9..6b39a8d 100644
--- a/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/LocalOrderProperty.java
+++ b/algebricks/algebricks-core/src/main/java/org/apache/hyracks/algebricks/core/algebra/properties/LocalOrderProperty.java
@@ -84,8 +84,12 @@
@Override
public boolean equals(Object object) {
- LocalOrderProperty lop = (LocalOrderProperty) object;
- return orderColumns.equals(lop.orderColumns);
+ if (object instanceof LocalOrderProperty) {
+ LocalOrderProperty lop = (LocalOrderProperty) object;
+ return orderColumns.equals(lop.orderColumns);
+ } else {
+ return false;
+ }
}
/**
diff --git a/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveRedundantVariablesRule.java b/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveRedundantVariablesRule.java
index 9e867df..eb72db0 100644
--- a/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveRedundantVariablesRule.java
+++ b/algebricks/algebricks-rewriter/src/main/java/org/apache/hyracks/algebricks/rewriter/rules/RemoveRedundantVariablesRule.java
@@ -100,7 +100,6 @@
equivalentVarsMap.put(rhs, equivalentVars);
}
equivalentVarsMap.put(lhs, equivalentVars);
- equivalentVars.get(0);
}
private boolean removeRedundantVariables(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
diff --git a/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/file/RecordWriter.java b/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/file/RecordWriter.java
index 1d45b22..2f6b53e 100644
--- a/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/file/RecordWriter.java
+++ b/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/file/RecordWriter.java
@@ -36,7 +36,7 @@
public RecordWriter(Object[] args) throws Exception {
OutputStream outputStream = createOutputStream(args);
if (outputStream != null) {
- bufferedWriter = new BufferedWriter(new OutputStreamWriter(createOutputStream(args)));
+ bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
} else {
bufferedWriter = null;
}
diff --git a/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/storage/am/rtree/RTreeCheckTuple.java b/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/storage/am/rtree/RTreeCheckTuple.java
index 160e25c..4f7066f 100644
--- a/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/storage/am/rtree/RTreeCheckTuple.java
+++ b/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/storage/am/rtree/RTreeCheckTuple.java
@@ -30,14 +30,18 @@
@Override
public boolean equals(Object o) {
- RTreeCheckTuple<T> other = (RTreeCheckTuple<T>) o;
- for (int i = 0; i < fields.length; i++) {
- int cmp = fields[i].compareTo(other.getField(i));
- if (cmp != 0) {
- return false;
+ if (o instanceof RTreeCheckTuple) {
+ RTreeCheckTuple<T> other = (RTreeCheckTuple<T>) o;
+ for (int i = 0; i < fields.length; i++) {
+ int cmp = fields[i].compareTo(other.getField(i));
+ if (cmp != 0) {
+ return false;
+ }
}
+ return true;
+ } else {
+ return false;
}
- return true;
}
public boolean intersect(T o) {