From ba219c0fe4095180e7c472a498aa88897b7d3b8b Mon Sep 17 00:00:00 2001 From: Chris Kilding <590569+chriskilding@users.noreply.github.com> Date: Tue, 17 Nov 2020 16:31:32 +0000 Subject: [PATCH 1/3] Remove joda-time library and use Java 8 time instead --- project.gradle | 9 ++-- .../format/common/DateTimeAttribute.java | 44 +++++++++---------- .../common/RFC3339DateTimeAttribute.java | 17 +++---- .../format/draftv3/DateAttribute.java | 19 ++++---- .../format/draftv3/TimeAttribute.java | 19 ++++---- .../helpers/AbstractDateFormatAttribute.java | 15 ++----- 6 files changed, 56 insertions(+), 67 deletions(-) diff --git a/project.gradle b/project.gradle index 3d2665129..01d066150 100644 --- a/project.gradle +++ b/project.gradle @@ -22,8 +22,8 @@ */ group = "com.github.java-json-tools"; version = "2.2.14"; -sourceCompatibility = JavaVersion.VERSION_1_7; -targetCompatibility = JavaVersion.VERSION_1_7; // defaults to sourceCompatibility +sourceCompatibility = JavaVersion.VERSION_1_8; +targetCompatibility = JavaVersion.VERSION_1_8; // defaults to sourceCompatibility project.ext { description = "A Java implementation of the JSON Schema specification"; @@ -38,7 +38,6 @@ dependencies { compile(group: "com.github.java-json-tools", name: "json-schema-core", version: "1.2.14"); // FIXME: 1.6.4 exists, but has different license (EDL 1.0, EPL 2.0). Can update? compile(group: "com.sun.mail", name: "mailapi", version: "1.6.2"); - compile(group: "joda-time", name: "joda-time", version: "2.10.5"); compile(group: "com.googlecode.libphonenumber", name: "libphonenumber", version: "8.11.1"); compile(group: "com.google.code.findbugs", name: "jsr305", version: "3.0.2"); compile(group: "net.sf.jopt-simple", name: "jopt-simple", version: "5.0.4"); @@ -57,9 +56,9 @@ javadoc { def currentJavaVersion = org.gradle.api.JavaVersion.current() // FIXME: https://github.com/gradle/gradle/issues/11182 if (currentJavaVersion.compareTo(org.gradle.api.JavaVersion.VERSION_1_9) >= 0) { - addStringOption("-release", "7"); + addStringOption("-release", "8"); } - links("https://docs.oracle.com/javase/7/docs/api/"); + links("https://docs.oracle.com/javase/8/docs/api/"); links("https://www.javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.2/"); links("https://fasterxml.github.io/jackson-databind/javadoc/2.11/"); links("https://fasterxml.github.io/jackson-core/javadoc/2.11/"); diff --git a/src/main/java/com/github/fge/jsonschema/format/common/DateTimeAttribute.java b/src/main/java/com/github/fge/jsonschema/format/common/DateTimeAttribute.java index 8aae60ad2..b1cc04a41 100644 --- a/src/main/java/com/github/fge/jsonschema/format/common/DateTimeAttribute.java +++ b/src/main/java/com/github/fge/jsonschema/format/common/DateTimeAttribute.java @@ -27,11 +27,10 @@ import com.github.fge.jsonschema.processors.data.FullData; import com.github.fge.msgsimple.bundle.MessageBundle; import com.google.common.collect.ImmutableList; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.DateTimeFormatterBuilder; -import org.joda.time.format.DateTimeParser; -import static org.joda.time.DateTimeFieldType.*; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; /** * Validator for the {@code date-time} format attribute @@ -45,25 +44,24 @@ public final class DateTimeAttribute private static final DateTimeFormatter FORMATTER; static { - final DateTimeParser secFracsParser = new DateTimeFormatterBuilder() - .appendLiteral('.').appendFractionOfSecond(1,12) - .toParser(); + final DateTimeFormatter secFracsParser = new DateTimeFormatterBuilder() + .appendFraction(ChronoField.OFFSET_SECONDS, 1, 9, true) + .toFormatter(); - DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); - - builder = builder.appendFixedDecimal(year(), 4) - .appendLiteral('-') - .appendFixedDecimal(monthOfYear(), 2) - .appendLiteral('-') - .appendFixedDecimal(dayOfMonth(), 2) - .appendLiteral('T') - .appendFixedDecimal(hourOfDay(), 2) - .appendLiteral(':') - .appendFixedDecimal(minuteOfHour(), 2) - .appendLiteral(':') - .appendFixedDecimal(secondOfMinute(), 2) - .appendOptional(secFracsParser) - .appendTimeZoneOffset("Z", false, 2, 2); + DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder() + .appendValue(ChronoField.YEAR, 4) + .appendLiteral('-') + .appendValue(ChronoField.MONTH_OF_YEAR, 2) + .appendLiteral('-') + .appendValue(ChronoField.DAY_OF_MONTH, 2) + .appendLiteral('T') + .appendValue(ChronoField.HOUR_OF_DAY, 2) + .appendLiteral(':') + .appendValue(ChronoField.MINUTE_OF_HOUR, 2) + .appendLiteral(':') + .appendValue(ChronoField.SECOND_OF_MINUTE, 2) + .appendOptional(secFracsParser) + .appendZoneOrOffsetId(); FORMATTER = builder.toFormatter(); } @@ -88,7 +86,7 @@ public void validate(final ProcessingReport report, final String value = data.getInstance().getNode().textValue(); try { - FORMATTER.parseDateTime(value); + FORMATTER.parse(value); } catch (IllegalArgumentException ignored) { report.error(newMsg(data, bundle, "err.format.invalidDate") .putArgument("value", value).putArgument("expected", FORMATS)); diff --git a/src/main/java/com/github/fge/jsonschema/format/common/RFC3339DateTimeAttribute.java b/src/main/java/com/github/fge/jsonschema/format/common/RFC3339DateTimeAttribute.java index 73c1e12af..b9d2537e7 100644 --- a/src/main/java/com/github/fge/jsonschema/format/common/RFC3339DateTimeAttribute.java +++ b/src/main/java/com/github/fge/jsonschema/format/common/RFC3339DateTimeAttribute.java @@ -2,9 +2,6 @@ import com.github.fge.jsonschema.cfg.ValidationConfiguration; import com.github.fge.jsonschema.library.DraftV4Library; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.DateTimeFormatterBuilder; -import org.joda.time.format.DateTimeParser; import com.github.fge.jackson.NodeType; import com.github.fge.jsonschema.core.exceptions.ProcessingException; @@ -15,6 +12,10 @@ import com.github.fge.msgsimple.bundle.MessageBundle; import com.google.common.collect.ImmutableList; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; + /** * A {@link DateTimeFormatter} for date and time format defined in RFC3339. * @@ -36,14 +37,14 @@ public class RFC3339DateTimeAttribute extends AbstractFormatAttribute { private static final DateTimeFormatter FORMATTER; static { - final DateTimeParser secFracsParser = new DateTimeFormatterBuilder() - .appendLiteral('.').appendFractionOfSecond(1,12) - .toParser(); + final DateTimeFormatter secFracsParser = new DateTimeFormatterBuilder() + .appendFraction(ChronoField.OFFSET_SECONDS, 1, 9, true) + .toFormatter(); DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder() .appendPattern("yyyy-MM-dd'T'HH:mm:ss") .appendOptional(secFracsParser) - .appendTimeZoneOffset("Z", true, 2, 2); + .appendZoneOrOffsetId(); FORMATTER = builder.toFormatter(); } @@ -69,7 +70,7 @@ public void validate(final ProcessingReport report, try { - FORMATTER.parseDateTime(value); + FORMATTER.parse(value); final String secFracsAndOffset = value.substring("yyyy-MM-ddTHH:mm:ss".length()); final String offset; diff --git a/src/main/java/com/github/fge/jsonschema/format/draftv3/DateAttribute.java b/src/main/java/com/github/fge/jsonschema/format/draftv3/DateAttribute.java index 0c32fb93f..3ce21479d 100644 --- a/src/main/java/com/github/fge/jsonschema/format/draftv3/DateAttribute.java +++ b/src/main/java/com/github/fge/jsonschema/format/draftv3/DateAttribute.java @@ -21,10 +21,10 @@ import com.github.fge.jsonschema.format.FormatAttribute; import com.github.fge.jsonschema.format.helpers.AbstractDateFormatAttribute; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.DateTimeFormatterBuilder; -import static org.joda.time.DateTimeFieldType.*; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; public final class DateAttribute extends AbstractDateFormatAttribute @@ -44,13 +44,12 @@ public static FormatAttribute getInstance() @Override protected DateTimeFormatter getFormatter() { - DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); - - builder = builder.appendFixedDecimal(year(), 4) - .appendLiteral('-') - .appendFixedDecimal(monthOfYear(), 2) - .appendLiteral('-') - .appendFixedDecimal(dayOfMonth(), 2); + DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder() + .appendValue(ChronoField.YEAR, 4) + .appendLiteral('-') + .appendValue(ChronoField.MONTH_OF_YEAR, 2) + .appendLiteral('-') + .appendValue(ChronoField.DAY_OF_MONTH, 2); return builder.toFormatter(); } diff --git a/src/main/java/com/github/fge/jsonschema/format/draftv3/TimeAttribute.java b/src/main/java/com/github/fge/jsonschema/format/draftv3/TimeAttribute.java index 3764af377..73ea62dc8 100644 --- a/src/main/java/com/github/fge/jsonschema/format/draftv3/TimeAttribute.java +++ b/src/main/java/com/github/fge/jsonschema/format/draftv3/TimeAttribute.java @@ -21,10 +21,10 @@ import com.github.fge.jsonschema.format.FormatAttribute; import com.github.fge.jsonschema.format.helpers.AbstractDateFormatAttribute; -import org.joda.time.format.DateTimeFormatter; -import org.joda.time.format.DateTimeFormatterBuilder; -import static org.joda.time.DateTimeFieldType.*; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; public final class TimeAttribute extends AbstractDateFormatAttribute @@ -44,13 +44,12 @@ public static FormatAttribute getInstance() @Override protected DateTimeFormatter getFormatter() { - DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder(); - - builder = builder.appendFixedDecimal(hourOfDay(), 2) - .appendLiteral(':') - .appendFixedDecimal(minuteOfHour(), 2) - .appendLiteral(':') - .appendFixedDecimal(secondOfMinute(), 2); + DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder() + .appendValue(ChronoField.HOUR_OF_DAY, 2) + .appendLiteral(':') + .appendValue(ChronoField.MINUTE_OF_HOUR, 2) + .appendLiteral(':') + .appendValue(ChronoField.SECOND_OF_MINUTE, 2); return builder.toFormatter(); } diff --git a/src/main/java/com/github/fge/jsonschema/format/helpers/AbstractDateFormatAttribute.java b/src/main/java/com/github/fge/jsonschema/format/helpers/AbstractDateFormatAttribute.java index 687452c1c..b99d91248 100644 --- a/src/main/java/com/github/fge/jsonschema/format/helpers/AbstractDateFormatAttribute.java +++ b/src/main/java/com/github/fge/jsonschema/format/helpers/AbstractDateFormatAttribute.java @@ -25,19 +25,12 @@ import com.github.fge.jsonschema.format.AbstractFormatAttribute; import com.github.fge.jsonschema.processors.data.FullData; import com.github.fge.msgsimple.bundle.MessageBundle; -import org.joda.time.format.DateTimeFormatter; -import java.text.SimpleDateFormat; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; /** * Abstract class for date/time related format attributes - * - *

Joda Time is used for - * date and time parsing: it can handle all defined formats, and catches more - * errors than the standard JDK's {@link SimpleDateFormat} does.

- * - *

Furthermore (and more importantly), unlike {@link SimpleDateFormat}, Joda - * Time's {@link DateTimeFormatter} is thread-safe!

*/ public abstract class AbstractDateFormatAttribute extends AbstractFormatAttribute @@ -61,8 +54,8 @@ public final void validate(final ProcessingReport report, final String value = data.getInstance().getNode().textValue(); try { - formatter.parseLocalDate(value); - } catch (IllegalArgumentException ignored) { + formatter.parse(value); + } catch (DateTimeParseException ignored) { report.error(newMsg(data, bundle, "err.format.invalidDate") .putArgument("value", value).putArgument("expected", format)); } From 7c2697945ff346e7185ff2b2dd21c8eef36e42d3 Mon Sep 17 00:00:00 2001 From: Chris Kilding <590569+chriskilding@users.noreply.github.com> Date: Tue, 17 Nov 2020 17:06:59 +0000 Subject: [PATCH 2/3] Reflect new max fraction length of 9 in tests and error messages --- .../format/common/DateTimeAttribute.java | 2 +- .../common/RFC3339DateTimeAttribute.java | 2 +- .../resources/format/common/date-time.json | 12 ------- .../resources/format/rfc3339/date-time.json | 32 ++++++------------- 4 files changed, 12 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/github/fge/jsonschema/format/common/DateTimeAttribute.java b/src/main/java/com/github/fge/jsonschema/format/common/DateTimeAttribute.java index b1cc04a41..c1577c845 100644 --- a/src/main/java/com/github/fge/jsonschema/format/common/DateTimeAttribute.java +++ b/src/main/java/com/github/fge/jsonschema/format/common/DateTimeAttribute.java @@ -39,7 +39,7 @@ public final class DateTimeAttribute extends AbstractFormatAttribute { private static final ImmutableList FORMATS = ImmutableList.of( - "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}Z" + "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}Z" ); private static final DateTimeFormatter FORMATTER; diff --git a/src/main/java/com/github/fge/jsonschema/format/common/RFC3339DateTimeAttribute.java b/src/main/java/com/github/fge/jsonschema/format/common/RFC3339DateTimeAttribute.java index b9d2537e7..5cbbc0d7f 100644 --- a/src/main/java/com/github/fge/jsonschema/format/common/RFC3339DateTimeAttribute.java +++ b/src/main/java/com/github/fge/jsonschema/format/common/RFC3339DateTimeAttribute.java @@ -31,7 +31,7 @@ public class RFC3339DateTimeAttribute extends AbstractFormatAttribute { private static final ImmutableList RFC3339_FORMATS = ImmutableList.of( - "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}((+|-)HH:mm|Z)" + "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}((+|-)HH:mm|Z)" ); private static final DateTimeFormatter FORMATTER; diff --git a/src/test/resources/format/common/date-time.json b/src/test/resources/format/common/date-time.json index f79dcc701..5d13fc20f 100644 --- a/src/test/resources/format/common/date-time.json +++ b/src/test/resources/format/common/date-time.json @@ -66,17 +66,5 @@ { "data": "2012-08-07T20:42:32.123456789Z", "valid": true - }, - { - "data": "2012-08-07T20:42:32.1234567890Z", - "valid": true - }, - { - "data": "2012-08-07T20:42:32.12345678901Z", - "valid": true - }, - { - "data": "2012-08-07T20:42:32.123456789012Z", - "valid": true } ] diff --git a/src/test/resources/format/rfc3339/date-time.json b/src/test/resources/format/rfc3339/date-time.json index 1ee20602d..f4e7bb9b9 100644 --- a/src/test/resources/format/rfc3339/date-time.json +++ b/src/test/resources/format/rfc3339/date-time.json @@ -33,7 +33,7 @@ "message": "err.format.invalidDate", "msgData": { "value": "201202030", - "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}((+|-)HH:mm|Z)" ] + "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}((+|-)HH:mm|Z)" ] }, "msgParams": [ "value", "expected" ] }, @@ -43,7 +43,7 @@ "message": "err.format.invalidDate", "msgData": { "value": "2012-12-02T13:05:00+0100", - "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}((+|-)HH:mm|Z)" ] + "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}((+|-)HH:mm|Z)" ] }, "msgParams": [ "value", "expected" ] }, @@ -53,7 +53,7 @@ "message": "err.format.invalidDate", "msgData": { "value": "2012-12-02T13:05:00+01:30:30", - "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}((+|-)HH:mm|Z)" ] + "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}((+|-)HH:mm|Z)" ] }, "msgParams": [ "value", "expected" ] }, @@ -63,7 +63,7 @@ "message": "err.format.invalidDate", "msgData": { "value": "2012-12-02T13:05:00Z[Europe/Paris]", - "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}((+|-)HH:mm|Z)" ] + "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}((+|-)HH:mm|Z)" ] }, "msgParams": [ "value", "expected" ] }, @@ -73,7 +73,7 @@ "message": "err.format.invalidDate", "msgData": { "value": "2012-12-02T13:05:00+10:00Z", - "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}((+|-)HH:mm|Z)" ] + "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}((+|-)HH:mm|Z)" ] }, "msgParams": [ "value", "expected" ] }, @@ -83,7 +83,7 @@ "message": "err.format.invalidDate", "msgData": { "value": "2012-12-02T13:05:00America/New_York", - "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}((+|-)HH:mm|Z)" ] + "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}((+|-)HH:mm|Z)" ] }, "msgParams": [ "value", "expected" ] }, @@ -93,7 +93,7 @@ "message": "err.format.invalidDate", "msgData": { "value": "2012-12-02T13:05:00[America/New_York]", - "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}((+|-)HH:mm|Z)" ] + "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}((+|-)HH:mm|Z)" ] }, "msgParams": [ "value", "expected" ] }, @@ -103,7 +103,7 @@ "message": "err.format.invalidDate", "msgData": { "value": "2012-12-02T13:05:00.123456", - "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}((+|-)HH:mm|Z)" ] + "expected": [ "yyyy-MM-dd'T'HH:mm:ss((+|-)HH:mm|Z)", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}((+|-)HH:mm|Z)" ] }, "msgParams": [ "value", "expected" ] }, @@ -136,19 +136,7 @@ "valid": true }, { - "data": "2012-08-07T20:42:32.1234567890Z", - "valid": true - }, - { - "data": "2012-08-07T20:42:32.12345678901Z", - "valid": true - }, - { - "data": "2012-08-07T20:42:32.123456789012Z", - "valid": true - }, - { - "data": "2012-08-07T20:42:32.123456789012+05:00", - "valid": true + "data": "2012-08-07T20:42:32.123456789+05:00", + "valid": true } ] From fcd47e5d97fd9db16775d8f9e4fe60ae04f1ec24 Mon Sep 17 00:00:00 2001 From: Chris Kilding <590569+chriskilding@users.noreply.github.com> Date: Tue, 17 Nov 2020 17:12:25 +0000 Subject: [PATCH 3/3] Catch DateTimeException as well as IllegalArgumentException for error reporting --- .../fge/jsonschema/format/common/DateTimeAttribute.java | 3 ++- .../jsonschema/format/common/RFC3339DateTimeAttribute.java | 3 ++- src/test/resources/format/common/date-time.json | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/github/fge/jsonschema/format/common/DateTimeAttribute.java b/src/main/java/com/github/fge/jsonschema/format/common/DateTimeAttribute.java index c1577c845..10ac129bb 100644 --- a/src/main/java/com/github/fge/jsonschema/format/common/DateTimeAttribute.java +++ b/src/main/java/com/github/fge/jsonschema/format/common/DateTimeAttribute.java @@ -30,6 +30,7 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; import java.time.temporal.ChronoField; /** @@ -87,7 +88,7 @@ public void validate(final ProcessingReport report, try { FORMATTER.parse(value); - } catch (IllegalArgumentException ignored) { + } catch (DateTimeParseException ignored) { report.error(newMsg(data, bundle, "err.format.invalidDate") .putArgument("value", value).putArgument("expected", FORMATS)); } diff --git a/src/main/java/com/github/fge/jsonschema/format/common/RFC3339DateTimeAttribute.java b/src/main/java/com/github/fge/jsonschema/format/common/RFC3339DateTimeAttribute.java index 5cbbc0d7f..204205420 100644 --- a/src/main/java/com/github/fge/jsonschema/format/common/RFC3339DateTimeAttribute.java +++ b/src/main/java/com/github/fge/jsonschema/format/common/RFC3339DateTimeAttribute.java @@ -14,6 +14,7 @@ import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatterBuilder; +import java.time.format.DateTimeParseException; import java.time.temporal.ChronoField; /** @@ -89,7 +90,7 @@ public void validate(final ProcessingReport report, throw new IllegalArgumentException(); } - } catch (IllegalArgumentException ignored) { + } catch (DateTimeParseException | IllegalArgumentException ignored) { report.error(newMsg(data, bundle, "err.format.invalidDate") .putArgument("value", value).putArgument("expected", RFC3339_FORMATS)); } diff --git a/src/test/resources/format/common/date-time.json b/src/test/resources/format/common/date-time.json index 5d13fc20f..1a89ddb25 100644 --- a/src/test/resources/format/common/date-time.json +++ b/src/test/resources/format/common/date-time.json @@ -25,7 +25,7 @@ "message": "err.format.invalidDate", "msgData": { "value": "2012-02-30T00:00:00+0000", - "expected": [ "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}Z" ] + "expected": [ "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}Z" ] }, "msgParams": [ "value", "expected" ] }, @@ -35,7 +35,7 @@ "message": "err.format.invalidDate", "msgData": { "value": "201202030", - "expected": [ "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,12}Z" ] + "expected": [ "yyyy-MM-dd'T'HH:mm:ssZ", "yyyy-MM-dd'T'HH:mm:ss.[0-9]{1,9}Z" ] }, "msgParams": [ "value", "expected" ] },