From 6f85e5e88a7239cd7c6199a21820f4178aa9e4a2 Mon Sep 17 00:00:00 2001 From: Henrik Nygren Date: Fri, 14 Oct 2016 13:39:05 +0300 Subject: [PATCH] Make parsing exercise deadlines thread safe Exercise#getDeadlineDate was randomly failing because SimpleDateFormat is not thread safe. --- src/main/java/fi/helsinki/cs/tmc/core/domain/Exercise.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/fi/helsinki/cs/tmc/core/domain/Exercise.java b/src/main/java/fi/helsinki/cs/tmc/core/domain/Exercise.java index 77faeef3..6dc0513b 100644 --- a/src/main/java/fi/helsinki/cs/tmc/core/domain/Exercise.java +++ b/src/main/java/fi/helsinki/cs/tmc/core/domain/Exercise.java @@ -20,8 +20,7 @@ public class Exercise implements Serializable { private static final Logger logger = LoggerFactory.getLogger(Exercise.class); - private static final DateFormat DATE_FORMAT = - new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX"); + private static final String DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSX"; private int id; private String name; @@ -138,8 +137,9 @@ public Date getDeadlineDate() { if (Strings.isNullOrEmpty(this.getDeadline())) { return null; } + final SimpleDateFormat dateFormatter = new SimpleDateFormat(DATE_FORMAT); try { - return DATE_FORMAT.parse(this.getDeadline()); + return dateFormatter.parse(this.getDeadline()); } catch (ParseException ex) { logger.warn("Failed to parse date {}", this.getDeadline(), ex); return null;