Skip to content

Commit 18eedbf

Browse files
author
Dmytro Chyzhykov
committed
Merge pull request cucumber#617 from cucumber/time-converter-simple-date-format-and-thread-safety
TimeConverter used to use the SimpleDateFormat
2 parents b79d402 + 404a702 commit 18eedbf

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

core/src/main/java/cucumber/runtime/xstream/TimeConverter.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
abstract class TimeConverter<T> extends ConverterWithFormat<T> {
1717
private final List<DateFormat> formats = new ArrayList<DateFormat>();
18-
private SimpleDateFormat onlyFormat;
18+
private String format;
1919

2020
TimeConverter(Locale locale, Class[] convertibleTypes) {
2121
super(convertibleTypes);
@@ -37,7 +37,14 @@ void add(DateFormat dateFormat) {
3737
}
3838

3939
public List<? extends Format> getFormats() {
40-
return onlyFormat == null ? formats : asList(onlyFormat);
40+
return format == null ? formats : asList(getOnlyFormat());
41+
}
42+
43+
private Format getOnlyFormat() {
44+
DateFormat dateFormat = new SimpleDateFormat(format, getLocale());
45+
dateFormat.setLenient(false);
46+
47+
return dateFormat;
4148
}
4249

4350
@Override
@@ -51,14 +58,14 @@ public String toString(Object obj) {
5158
@Override
5259
public void setParameterInfoAndLocale(ParameterInfo parameterInfo, Locale locale) {
5360
super.setParameterInfoAndLocale(parameterInfo, locale);
61+
5462
if (parameterInfo.getFormat() != null) {
55-
onlyFormat = new SimpleDateFormat(parameterInfo.getFormat(), locale);
56-
onlyFormat.setLenient(false);
63+
format = parameterInfo.getFormat();
5764
}
5865
}
5966

6067
public void removeOnlyFormat() {
61-
onlyFormat = null;
68+
format = null;
6269
}
6370

6471
public static List<Class> getTimeClasses() {

0 commit comments

Comments
 (0)