From e0dea0c27ebd21ba2d0dd321182304c5543410ab Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Thu, 19 Nov 2015 11:52:17 +0200 Subject: [PATCH] EstimatedHistogram: Support empty histogram When creating an estimated histogram from buckets it is a valid option to get a zero size array as the buckets array. In that case the newOffsets method would get a negative value for its size, which should result in a zero length array of offsets. Signed-off-by: Amnon Heiman --- .../java/com/cloudius/urchin/utils/EstimatedHistogram.java | 3 +++ 1 file changed, 3 insertions(+) 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;