@@ -39,6 +39,10 @@ public DateTimeValidator(String schemaPath, JsonNode schemaNode, JsonSchema pare
39
39
this .formatName = formatName ;
40
40
this .validationContext = validationContext ;
41
41
parseErrorCode (getValidatorType ().getErrorCodeKey ());
42
+
43
+ if (!formatName .equals (DATE ) && !formatName .equals (DATETIME )) {
44
+ throw new IllegalArgumentException (String .format ("formatName must be one of the following: [%s, %s]" , DATE , DATETIME ));
45
+ }
42
46
}
43
47
44
48
public Set <ValidationMessage > validate (JsonNode node , JsonNode rootNode , String at ) {
@@ -57,29 +61,22 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
57
61
}
58
62
59
63
private boolean isLegalDateTime (String string ) {
60
- if ( formatName . equals ( DATE )) {
61
- return tryParse (() -> LocalDate . parse ( string ));
62
- } else if ( formatName . equals ( DATETIME )) {
63
- return tryParse (() -> {
64
+ try {
65
+ if ( formatName . equals ( DATE )) {
66
+ LocalDate . parse ( string );
67
+ } else if ( formatName . equals ( DATETIME )) {
64
68
try {
65
69
ITU .parseDateTime (string );
66
70
} catch (LeapSecondException ex ) {
67
- if (!ex .isVerifiedValidLeapYearMonth ()) {
68
- throw ex ;
71
+ if (!ex .isVerifiedValidLeapYearMonth ()) {
72
+ return false ;
69
73
}
70
74
}
71
- });
72
- } else {
73
- throw new IllegalStateException ("Unknown format: " + formatName );
74
- }
75
- }
75
+ }
76
76
77
- private boolean tryParse (Runnable parser ) {
78
- try {
79
- parser .run ();
80
77
return true ;
81
78
} catch (Exception ex ) {
82
- logger .error ("Invalid {}: {}" , formatName , ex .getMessage ());
79
+ logger .debug ("Invalid {}: {}" , formatName , ex .getMessage ());
83
80
return false ;
84
81
}
85
82
}
0 commit comments