diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/Jsr310DateTimeFormatAnnotationFormatterFactory.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/Jsr310DateTimeFormatAnnotationFormatterFactory.java index a1fd17fe21..72679a427b 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/Jsr310DateTimeFormatAnnotationFormatterFactory.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/Jsr310DateTimeFormatAnnotationFormatterFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -96,6 +96,8 @@ public class Jsr310DateTimeFormatAnnotationFormatterFactory extends EmbeddedValu @Override @SuppressWarnings("unchecked") public Parser getParser(DateTimeFormat annotation, Class fieldType) { + DateTimeFormatter formatter = getFormatter(annotation, fieldType); + List resolvedFallbackPatterns = new ArrayList<>(); for (String fallbackPattern : annotation.fallbackPatterns()) { String resolvedFallbackPattern = resolveEmbeddedValue(fallbackPattern); @@ -104,7 +106,6 @@ public class Jsr310DateTimeFormatAnnotationFormatterFactory extends EmbeddedValu } } - DateTimeFormatter formatter = getFormatter(annotation, fieldType); return new TemporalAccessorParser((Class) fieldType, formatter, resolvedFallbackPatterns.toArray(new String[0]), annotation); } diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorParser.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorParser.java index b8dd20fe01..59c35f1ad3 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorParser.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,7 +71,8 @@ public final class TemporalAccessorParser implements Parser { } TemporalAccessorParser(Class temporalAccessorType, DateTimeFormatter formatter, - @Nullable String[] fallbackPatterns, @Nullable Object source) { + @Nullable String[] fallbackPatterns, @Nullable Object source) { + this.temporalAccessorType = temporalAccessorType; this.formatter = formatter; this.fallbackPatterns = fallbackPatterns; @@ -100,8 +101,8 @@ public final class TemporalAccessorParser implements Parser { } if (this.source != null) { throw new DateTimeParseException( - String.format("Unable to parse date time value \"%s\" using configuration from %s", text, this.source), - text, ex.getErrorIndex(), ex); + String.format("Unable to parse date time value \"%s\" using configuration from %s", text, this.source), + text, ex.getErrorIndex(), ex); } // else rethrow original exception throw ex;