diff --git a/src/main/java/com/cloudius/urchin/api/APIClient.java b/src/main/java/com/cloudius/urchin/api/APIClient.java index c80a658..90fdd53 100644 --- a/src/main/java/com/cloudius/urchin/api/APIClient.java +++ b/src/main/java/com/cloudius/urchin/api/APIClient.java @@ -677,6 +677,9 @@ public class APIClient { MultivaluedMap queryParams) { JsonObject obj = getJsonObj(string, queryParams); JsonArray arr = obj.getJsonArray("buckets"); + if (arr == null) { + return new long[0]; + } long res[] = new long[arr.size()]; for (int i = 0; i< arr.size(); i++) { res[i] = arr.getJsonNumber(i).longValue(); diff --git a/src/main/java/com/cloudius/urchin/utils/EstimatedHistogram.java b/src/main/java/com/cloudius/urchin/utils/EstimatedHistogram.java index 29bf21b..644e67b 100644 --- a/src/main/java/com/cloudius/urchin/utils/EstimatedHistogram.java +++ b/src/main/java/com/cloudius/urchin/utils/EstimatedHistogram.java @@ -74,6 +74,9 @@ public class EstimatedHistogram { } private static long[] newOffsets(int size) { + if (size <= 0) { + return new long[0]; + } long[] result = new long[size]; long last = 1; result[0] = last; diff --git a/src/main/java/com/cloudius/urchin/utils/RecentEstimatedHistogram.java b/src/main/java/com/cloudius/urchin/utils/RecentEstimatedHistogram.java index 692f41e..4f43690 100644 --- a/src/main/java/com/cloudius/urchin/utils/RecentEstimatedHistogram.java +++ b/src/main/java/com/cloudius/urchin/utils/RecentEstimatedHistogram.java @@ -50,6 +50,9 @@ public class RecentEstimatedHistogram extends EstimatedHistogram { * @return a long[] containing the current histogram difference buckets */ public long[] getBuckets(long[] bucketData) { + if (bucketData.length == 0) { + return new long[0]; + } final int len = buckets.length(); long[] rv = new long[len];