diff --git a/src/main/java/com/greplin/interval/NumericIntervalField.java b/src/main/java/com/greplin/interval/NumericIntervalField.java index 655429d..ef5f1a3 100644 --- a/src/main/java/com/greplin/interval/NumericIntervalField.java +++ b/src/main/java/com/greplin/interval/NumericIntervalField.java @@ -118,9 +118,13 @@ public TokenStream tokenStreamValue() { static long[] splitParts(final String rangeString) { String trimmed = rangeString.trim(); int middle = trimmed.indexOf('-', 1); - long start = Long.parseLong(trimmed.substring(0, middle).trim()); - long end = Long.parseLong(trimmed.substring(middle + 1).trim()); - return new long[]{start, end}; + try { + long start = Long.parseLong(trimmed.substring(0, middle).trim()); + long end = Long.parseLong(trimmed.substring(middle + 1).trim()); + return new long[]{start, end}; + } catch (NumberFormatException e) { + throw new NumberFormatException("Passed value does not contain two parsable long values"); + } } /** diff --git a/src/test/java/com/greplin/interval/NumericIntervalFieldTest.java b/src/test/java/com/greplin/interval/NumericIntervalFieldTest.java index b9c24b9..170fd7d 100644 --- a/src/test/java/com/greplin/interval/NumericIntervalFieldTest.java +++ b/src/test/java/com/greplin/interval/NumericIntervalFieldTest.java @@ -54,4 +54,9 @@ public void testSplitParts() { Assert.assertArrayEquals(new long[]{-100, 21253456}, NumericIntervalField.splitParts("-100-21253456")); } + + @Test (expected=NumberFormatException.class) + public void testEmptyNumbers() throws Exception { + long[] result = NumericIntervalField.splitParts("null-null"); + } }