Skip to content

Commit

Permalink
Date handling: Unify exception handling between joda/javatime
Browse files Browse the repository at this point in the history
Due to the change in exception handling in elastic#36447 the backport now used
different exceptions on parser failures between java and joda time
formatting. This uses now IllegalArgumentExceptions for formatting
errors all over the place.

Closes elastic#36598
  • Loading branch information
spinscale committed Dec 13, 2018
1 parent 0e6afcb commit 45953a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ class JavaDateFormatter implements DateFormatter {

@Override
public TemporalAccessor parse(String input) {
DateTimeParseException failure = null;
IllegalArgumentException failure = null;
for (int i = 0; i < parsers.length; i++) {
try {
return parsers[i].parse(input);
} catch (DateTimeParseException e) {
if (failure == null) {
failure = e;
failure = new IllegalArgumentException(e);
} else {
failure.addSuppressed(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.TemporalAccessor;
import java.util.Locale;

Expand Down Expand Up @@ -519,7 +518,8 @@ private void assertJodaParseException(String input, String format, String expect

private void assertJavaTimeParseException(String input, String format, String expectedMessage) {
DateFormatter javaTimeFormatter = DateFormatters.forPattern(format);
DateTimeParseException dateTimeParseException = expectThrows(DateTimeParseException.class, () -> javaTimeFormatter.parse(input));
assertThat(dateTimeParseException.getMessage(), startsWith(expectedMessage));
IllegalArgumentException dateTimeParseException =
expectThrows(IllegalArgumentException.class, () -> javaTimeFormatter.parse(input));
assertThat(dateTimeParseException.getCause().getMessage(), startsWith(expectedMessage));
}
}

0 comments on commit 45953a4

Please sign in to comment.