Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumericIntervalField does not catch NumberFormatException #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/main/java/com/greplin/interval/NumericIntervalField.java
Expand Up @@ -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");
}
}

/**
Expand Down
Expand Up @@ -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");
}
}