You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by ni...@apache.org on 2019/12/25 12:21:05 UTC
[kylin] branch master updated: KYLIN-4311 fix noncompliant
interator issue in sonar
This is an automated email from the ASF dual-hosted git repository.
nic pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kylin.git
The following commit(s) were added to refs/heads/master by this push:
new 0f86e20 KYLIN-4311 fix noncompliant interator issue in sonar
0f86e20 is described below
commit 0f86e20154d5913693c13a390f28b70ad6100ef7
Author: etherge <et...@163.com>
AuthorDate: Fri Dec 20 18:13:19 2019 -0500
KYLIN-4311 fix noncompliant interator issue in sonar
---
.../src/main/java/org/apache/kylin/common/util/FIFOIterator.java | 4 ++++
.../src/main/java/org/apache/kylin/common/util/ImmutableBitSet.java | 4 ++++
.../main/java/org/apache/kylin/source/datagen/ColumnGenerator.java | 6 +++++-
.../apache/kylin/storage/hbase/cube/v2/ExpectedSizeIterator.java | 3 ++-
4 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/core-common/src/main/java/org/apache/kylin/common/util/FIFOIterator.java b/core-common/src/main/java/org/apache/kylin/common/util/FIFOIterator.java
index ccea37c..7dd824c 100644
--- a/core-common/src/main/java/org/apache/kylin/common/util/FIFOIterator.java
+++ b/core-common/src/main/java/org/apache/kylin/common/util/FIFOIterator.java
@@ -18,6 +18,7 @@
package org.apache.kylin.common.util;
import java.util.Iterator;
+import java.util.NoSuchElementException;
import java.util.Queue;
/**
@@ -40,6 +41,9 @@ public class FIFOIterator<T> implements Iterator<T> {
@Override
public T next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
return q.poll();
}
diff --git a/core-common/src/main/java/org/apache/kylin/common/util/ImmutableBitSet.java b/core-common/src/main/java/org/apache/kylin/common/util/ImmutableBitSet.java
index 5cdf08c..20a0d21 100644
--- a/core-common/src/main/java/org/apache/kylin/common/util/ImmutableBitSet.java
+++ b/core-common/src/main/java/org/apache/kylin/common/util/ImmutableBitSet.java
@@ -20,6 +20,7 @@ package org.apache.kylin.common.util;
import java.nio.ByteBuffer;
import java.util.BitSet;
import java.util.Iterator;
+import java.util.NoSuchElementException;
public class ImmutableBitSet implements Iterable<Integer> {
@@ -186,6 +187,9 @@ public class ImmutableBitSet implements Iterable<Integer> {
@Override
public Integer next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
return arr[index++];
}
diff --git a/core-metadata/src/main/java/org/apache/kylin/source/datagen/ColumnGenerator.java b/core-metadata/src/main/java/org/apache/kylin/source/datagen/ColumnGenerator.java
index b6c48fd..2c4338b 100644
--- a/core-metadata/src/main/java/org/apache/kylin/source/datagen/ColumnGenerator.java
+++ b/core-metadata/src/main/java/org/apache/kylin/source/datagen/ColumnGenerator.java
@@ -28,6 +28,7 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
+import java.util.NoSuchElementException;
import java.util.Random;
import java.util.TreeSet;
@@ -179,7 +180,7 @@ public class ColumnGenerator {
// double
return formatNumber(randomDouble());
} else {
- throw new IllegalStateException();
+ throw new NoSuchElementException();
}
}
@@ -224,6 +225,9 @@ public class ColumnGenerator {
@Override
public String next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
return "" + (next++);
}
}
diff --git a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/ExpectedSizeIterator.java b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/ExpectedSizeIterator.java
index 2cb0c7f..bddb5fd 100644
--- a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/ExpectedSizeIterator.java
+++ b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/cube/v2/ExpectedSizeIterator.java
@@ -19,6 +19,7 @@
package org.apache.kylin.storage.hbase.cube.v2;
import java.util.Iterator;
+import java.util.NoSuchElementException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
@@ -55,7 +56,7 @@ class ExpectedSizeIterator implements Iterator<byte[]> {
@Override
public byte[] next() {
if (current >= expectedSize) {
- throw new IllegalStateException("Won't have more data");
+ throw new NoSuchElementException("Won't have more data");
}
try {
current++;