More Coverity Fixes
- CID 68210 (#1 of 1): Check of thread-shared field evades lock
acquisition (LOCK_EVASION)
6. thread1_overwrites_value_in_field: Thread1 sets index to a new
value. Now the two threads have an inconsistent view of index and
updates to fields of index or fields correlated with index may be
lost.
- CID 68209 (#1 of 1): Check of thread-shared field evades lock
acquisition (LOCK_EVASION)
6. thread1_overwrites_value_in_field: Thread1 sets index to a new
value. Now the two threads have an inconsistent view of index and
updates to fields of index or fields correlated with index may be
lost.
- CID 68208 (#1 of 1): Check of thread-shared field evades lock
acquisition (LOCK_EVASION)
6. thread1_overwrites_value_in_field: Thread1 sets index to a new
value. Now the two threads have an inconsistent view of index and
updates to fields of index or fields correlated with index may be
lost.
- CID 68435 (#1 of 1): UR: Uninitialized read of field in constructor
(FB.UR_UNINIT_READ)
1. defect: Uninitialized read of btreeCmp.
- CID 68416 (#1 of 1): UL: Lock not released on all paths
(FB.UL_UNRELEASED_LOCK_EXCEPTION_PATH)
1. defect:
org.apache.hyracks.storage.am.lsm.invertedindex.inmemory.PartitionedIn
MemoryInvertedIndex.updatePartitionIndexes(short) does not release
lock on all exception paths.
- CID 68415 (#1 of 1): UL: Lock not released on all paths
(FB.UL_UNRELEASED_LOCK)
1. defect:
org.apache.hyracks.storage.common.buffercache.BufferCache.sweepAndFlus
h(int, boolean) does not release lock on all paths.
- CID 68414 (#1 of 1): UL: Lock not released on all paths
(FB.UL_UNRELEASED_LOCK)
1. defect:
org.apache.hyracks.storage.common.buffercache.BufferCache.dumpState()
does not release lock on all paths.
- CID 68412 (#1 of 1): UL: Lock not released on all paths
(FB.UL_UNRELEASED_LOCK)
1. defect:
org.apache.hyracks.storage.am.lsm.common.impls.VirtualBufferCache.dele
teFile(int, boolean) does not release lock on all paths.
- CID 68337 (#1 of 1): RV: Bad use of return value
(FB.RV_ABSOLUTE_VALUE_OF_RANDOM_INT)
1. defect: Bad attempt to compute absolute value of signed random
integer.
- CID 68336 (#1 of 1): RV: Bad use of return value
(FB.RV_ABSOLUTE_VALUE_OF_RANDOM_INT)
1. defect: Bad attempt to compute absolute value of signed random
integer.
- CID 68335 (#1 of 1): RV: Bad use of return value
(FB.RV_ABSOLUTE_VALUE_OF_RANDOM_INT)
1. defect: Bad attempt to compute absolute value of signed random
integer.
- CID 68334 (#1 of 1): RV: Bad use of return value
(FB.RV_ABSOLUTE_VALUE_OF_RANDOM_INT)
1. defect: Bad attempt to compute absolute value of signed random
integer.
- CID 68259 (#1 of 1): Result is not floating-point
(UNINTENDED_INTEGER_DIVISION)
integer_division: Dividing integer expressions 2147483647 and 2, and
then converting the integer quotient to type double. Any remainder,
or fractional part of the quotient, is ignored.
Change-Id: I0f63f7fb75b1ac8ffc1fc1d70e66bb19b788fe8e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/661
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ian Maxon <imaxon@apache.org>
diff --git a/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/structures/AbstractHeap.java b/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/structures/AbstractHeap.java
index a0abaf7..c6ca09b 100644
--- a/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/structures/AbstractHeap.java
+++ b/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/structures/AbstractHeap.java
@@ -21,7 +21,7 @@
import java.util.Arrays;
-import org.apache.hyracks.dataflow.std.util.MathUtil;
+import org.apache.hyracks.util.MathUtil;
public abstract class AbstractHeap implements IHeap<IResetableComparable> {
protected static final int NOT_EXIST = -1;
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/DocumentStringFieldValueGenerator.java b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/DocumentStringFieldValueGenerator.java
index cff11dc..1e8077c 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/DocumentStringFieldValueGenerator.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/DocumentStringFieldValueGenerator.java
@@ -27,6 +27,8 @@
import java.util.List;
import java.util.Random;
+import org.apache.hyracks.util.MathUtil;
+
public class DocumentStringFieldValueGenerator implements IFieldValueGenerator<String> {
private final String FIRST_NAMES_FILE = "dist.all.first.cleaned";
private final String LAST_NAMES_FILE = "dist.all.last.cleaned";
@@ -82,7 +84,7 @@
@Override
public String next() {
StringBuilder strBuilder = new StringBuilder();
- int numWords = Math.abs(rnd.nextInt()) % (docMaxWords - docMinWords + 1) + docMinWords;
+ int numWords = MathUtil.stripSignBit(rnd.nextInt()) % (docMaxWords - docMinWords + 1) + docMinWords;
for (int i = 0; i < numWords; i++) {
int ix = ProbabilityHelper.choose(cumulIntRanges, rnd.nextInt());
strBuilder.append(tokenDict.get(ix));
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/PersonNameFieldValueGenerator.java b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/PersonNameFieldValueGenerator.java
index 49edafb..5af0b0f 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/PersonNameFieldValueGenerator.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/PersonNameFieldValueGenerator.java
@@ -27,6 +27,8 @@
import java.util.List;
import java.util.Random;
+import org.apache.hyracks.util.MathUtil;
+
public class PersonNameFieldValueGenerator implements IFieldValueGenerator<String> {
private final String FIRST_NAMES_FILE = "dist.all.first.cleaned";
private final String LAST_NAMES_FILE = "dist.all.last.cleaned";
@@ -76,20 +78,20 @@
StringBuilder strBuilder = new StringBuilder();
// First name.
- int fix = Math.abs(rnd.nextInt()) % firstNames.size();
+ int fix = MathUtil.stripSignBit(rnd.nextInt()) % firstNames.size();
strBuilder.append(firstNames.get(fix));
strBuilder.append(" ");
// Optional middle initial.
double d = Math.abs(rnd.nextDouble());
if (d <= middleInitialProb) {
- int mix = Math.abs(rnd.nextInt()) % letters.length();
+ int mix = MathUtil.stripSignBit(rnd.nextInt()) % letters.length();
strBuilder.append(letters.charAt(mix));
strBuilder.append(". ");
}
// Last name.
- int lix = Math.abs(rnd.nextInt()) % lastNames.size();
+ int lix = MathUtil.stripSignBit(rnd.nextInt()) % lastNames.size();
strBuilder.append(lastNames.get(lix));
return strBuilder.toString();
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/StringFieldValueGenerator.java b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/StringFieldValueGenerator.java
index c337462..9418447 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/StringFieldValueGenerator.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/datagen/StringFieldValueGenerator.java
@@ -21,6 +21,8 @@
import java.util.Random;
+import org.apache.hyracks.util.MathUtil;
+
public class StringFieldValueGenerator implements IFieldValueGenerator<String> {
private int maxLen;
private final Random rnd;
@@ -39,7 +41,7 @@
String s = Long.toHexString(Double.doubleToLongBits(rnd.nextDouble()));
StringBuilder strBuilder = new StringBuilder();
for (int i = 0; i < s.length() && i < maxLen; i++) {
- strBuilder.append(s.charAt(Math.abs(rnd.nextInt()) % s.length()));
+ strBuilder.append(s.charAt(MathUtil.stripSignBit(rnd.nextInt()) % s.length()));
}
return strBuilder.toString();
}
diff --git a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/util/TreeIndexBufferCacheWarmup.java b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/util/TreeIndexBufferCacheWarmup.java
index 398a3f3..d9013d3 100644
--- a/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/util/TreeIndexBufferCacheWarmup.java
+++ b/hyracks/hyracks-storage-am-common/src/main/java/org/apache/hyracks/storage/am/common/util/TreeIndexBufferCacheWarmup.java
@@ -22,6 +22,7 @@
import java.util.Random;
import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.util.MathUtil;
import org.apache.hyracks.storage.am.common.api.IMetaDataPageManager;
import org.apache.hyracks.storage.am.common.api.ITreeIndexFrame;
import org.apache.hyracks.storage.am.common.api.ITreeIndexMetaDataFrame;
@@ -84,7 +85,7 @@
int remainingLength = pageIds.size();
for (int j = 0; j < pageIds.size(); j++) {
- int index = Math.abs(rnd.nextInt()) % remainingLength;
+ int index = MathUtil.stripSignBit(rnd.nextInt()) % remainingLength;
int pageId = remainingPageIds[index];
// pin & latch then immediately unlatch & unpin
diff --git a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java
index 44d81ab..c82bf28 100644
--- a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java
+++ b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeDataflowHelper.java
@@ -56,13 +56,16 @@
@Override
public IIndex getIndexInstance() {
- if (index != null)
+ if (index != null) {
return index;
+ }
synchronized (lcManager) {
- try {
- index = lcManager.getIndex(resourcePath);
- } catch (HyracksDataException e) {
- return null;
+ if (index == null) {
+ try {
+ index = lcManager.getIndex(resourcePath);
+ } catch (HyracksDataException e) {
+ return null;
+ }
}
}
return index;
diff --git a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java
index 81beadd..56e9014 100644
--- a/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java
+++ b/hyracks/hyracks-storage-am-lsm-btree/src/main/java/org/apache/hyracks/storage/am/lsm/btree/dataflow/ExternalBTreeWithBuddyDataflowHelper.java
@@ -57,13 +57,16 @@
@Override
public IIndex getIndexInstance() {
- if (index != null)
+ if (index != null) {
return index;
+ }
synchronized (lcManager) {
- try {
- index = lcManager.getIndex(resourcePath);
- } catch (HyracksDataException e) {
- return null;
+ if (index == null) {
+ try {
+ index = lcManager.getIndex(resourcePath);
+ } catch (HyracksDataException e) {
+ return null;
+ }
}
}
return index;
diff --git a/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java b/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java
index 272f970..6b8cf35 100644
--- a/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java
+++ b/hyracks/hyracks-storage-am-lsm-common/src/main/java/org/apache/hyracks/storage/am/lsm/common/impls/VirtualBufferCache.java
@@ -96,7 +96,7 @@
}
for (int i = 0; i < buckets.length; i++) {
- CacheBucket bucket = buckets[i];
+ final CacheBucket bucket = buckets[i];
bucket.bucketLock.lock();
try {
VirtualPage prev = null;
diff --git a/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/PartitionedInMemoryInvertedIndex.java b/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/PartitionedInMemoryInvertedIndex.java
index 273aa16..39dcd4a 100644
--- a/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/PartitionedInMemoryInvertedIndex.java
+++ b/hyracks/hyracks-storage-am-lsm-invertedindex/src/main/java/org/apache/hyracks/storage/am/lsm/invertedindex/inmemory/PartitionedInMemoryInvertedIndex.java
@@ -72,13 +72,16 @@
public void updatePartitionIndexes(short numTokens) {
partitionIndexLock.writeLock().lock();
- if (numTokens < minPartitionIndex) {
- minPartitionIndex = numTokens;
+ try {
+ if (numTokens < minPartitionIndex) {
+ minPartitionIndex = numTokens;
+ }
+ if (numTokens > maxPartitionIndex) {
+ maxPartitionIndex = numTokens;
+ }
+ } finally {
+ partitionIndexLock.writeLock().unlock();
}
- if (numTokens > maxPartitionIndex) {
- maxPartitionIndex = numTokens;
- }
- partitionIndexLock.writeLock().unlock();
}
@Override
diff --git a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java
index 6f1c34a..48cc476 100644
--- a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java
+++ b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/dataflow/ExternalRTreeDataflowHelper.java
@@ -72,13 +72,16 @@
@Override
public IIndex getIndexInstance() {
- if (index != null)
+ if (index != null) {
return index;
+ }
synchronized (lcManager) {
- try {
- index = lcManager.getIndex(resourcePath);
- } catch (HyracksDataException e) {
- return null;
+ if (index == null) {
+ try {
+ index = lcManager.getIndex(resourcePath);
+ } catch (HyracksDataException e) {
+ return null;
+ }
}
}
return index;
diff --git a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeAbstractCursor.java b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeAbstractCursor.java
index d5257fe..c8f05c2 100644
--- a/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeAbstractCursor.java
+++ b/hyracks/hyracks-storage-am-lsm-rtree/src/main/java/org/apache/hyracks/storage/am/lsm/rtree/impls/LSMRTreeAbstractCursor.java
@@ -67,7 +67,7 @@
public LSMRTreeAbstractCursor(ILSMIndexOperationContext opCtx) {
this.opCtx = opCtx;
- btreeRangePredicate = new RangePredicate(null, null, true, true, btreeCmp, btreeCmp);
+ btreeRangePredicate = new RangePredicate(null, null, true, true, null, null);
}
public RTreeSearchCursor getCursor(int cursorIndex) {
diff --git a/hyracks/hyracks-storage-am-rtree/src/main/java/org/apache/hyracks/storage/am/rtree/linearize/ZCurveIntComparator.java b/hyracks/hyracks-storage-am-rtree/src/main/java/org/apache/hyracks/storage/am/rtree/linearize/ZCurveIntComparator.java
index f62ae27..2f372e2 100644
--- a/hyracks/hyracks-storage-am-rtree/src/main/java/org/apache/hyracks/storage/am/rtree/linearize/ZCurveIntComparator.java
+++ b/hyracks/hyracks-storage-am-rtree/src/main/java/org/apache/hyracks/storage/am/rtree/linearize/ZCurveIntComparator.java
@@ -21,7 +21,6 @@
import org.apache.hyracks.api.dataflow.value.ILinearizeComparator;
import org.apache.hyracks.data.std.primitive.DoublePointable;
import org.apache.hyracks.data.std.primitive.IntegerPointable;
-import org.apache.hyracks.dataflow.common.data.marshalling.IntegerSerializerDeserializer;
import org.apache.hyracks.storage.am.common.ophelpers.DoubleArrayList;
/*
@@ -48,7 +47,7 @@
}
private void resetStateMachine() {
- stepsize = Integer.MAX_VALUE / 2;
+ stepsize = Integer.MAX_VALUE / 2.0f;
bounds = new double[dim];
boundsStack.clear();
}
diff --git a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
index 75adfc9..27d0423 100644
--- a/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
+++ b/hyracks/hyracks-storage-common/src/main/java/org/apache/hyracks/storage/common/buffercache/BufferCache.java
@@ -448,7 +448,7 @@
buffer.append("cpid -> [fileId:pageId, pinCount, valid/invalid, confiscated/physical, dirty/clean]");
int nCachedPages = 0;
for (int i = 0; i < pageMap.length; ++i) {
- CacheBucket cb = pageMap[i];
+ final CacheBucket cb = pageMap[i];
cb.bucketLock.lock();
try {
CachedPage cp = cb.cachedPage;
@@ -786,7 +786,7 @@
private void sweepAndFlush(int fileId, boolean flushDirtyPages) throws HyracksDataException {
for (int i = 0; i < pageMap.length; ++i) {
- CacheBucket bucket = pageMap[i];
+ final CacheBucket bucket = pageMap[i];
bucket.bucketLock.lock();
try {
CachedPage prev = bucket.cachedPage;
diff --git a/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/util/MathUtil.java b/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MathUtil.java
similarity index 92%
rename from hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/util/MathUtil.java
rename to hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MathUtil.java
index ebdeeefc..2b157e4 100644
--- a/hyracks/hyracks-dataflow-std/src/main/java/org/apache/hyracks/dataflow/std/util/MathUtil.java
+++ b/hyracks/hyracks-util/src/main/java/org/apache/hyracks/util/MathUtil.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.hyracks.dataflow.std.util;
+package org.apache.hyracks.util;
public class MathUtil {
/**
@@ -51,4 +51,8 @@
return log + (n >>> 1);
}
+
+ public static int stripSignBit(int n) {
+ return n & 0x7fffffff;
+ }
}
diff --git a/hyracks/hyracks-dataflow-std/src/test/java/org/apache/hyracks/dataflow/std/util/MathTest.java b/hyracks/hyracks-util/src/test/java/org/apache/hyracks/util/MathTest.java
similarity index 96%
rename from hyracks/hyracks-dataflow-std/src/test/java/org/apache/hyracks/dataflow/std/util/MathTest.java
rename to hyracks/hyracks-util/src/test/java/org/apache/hyracks/util/MathTest.java
index 3c8af9f..c3443c8 100644
--- a/hyracks/hyracks-dataflow-std/src/test/java/org/apache/hyracks/dataflow/std/util/MathTest.java
+++ b/hyracks/hyracks-util/src/test/java/org/apache/hyracks/util/MathTest.java
@@ -17,14 +17,14 @@
* under the License.
*/
-package org.apache.hyracks.dataflow.std.util;
-
-import static org.junit.Assert.assertTrue;
+package org.apache.hyracks.util;
import java.util.Random;
import org.junit.Test;
+import static org.junit.Assert.assertTrue;
+
public class MathTest {
@Test