You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2016/12/21 15:58:04 UTC

[08/11] ant git commit: fix SimpleDateFormat cases (the instances are used single threaded)

fix SimpleDateFormat cases (the instances are used single threaded)


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/8e56f57a
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/8e56f57a
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/8e56f57a

Branch: refs/heads/1.9.x
Commit: 8e56f57ab5a1250379ba486048c52ef2e29c882d
Parents: 9d11861
Author: Stefan Bodewig <bo...@apache.org>
Authored: Wed Dec 21 16:01:47 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Wed Dec 21 16:01:47 2016 +0100

----------------------------------------------------------------------
 .../tools/ant/taskdefs/cvslib/ChangeLogParser.java | 17 ++++++++---------
 .../tools/ant/taskdefs/cvslib/ChangeLogWriter.java | 14 +++++++-------
 2 files changed, 15 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/8e56f57a/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java b/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java
index 0096aad..b088107 100644
--- a/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java
+++ b/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParser.java
@@ -44,21 +44,16 @@ class ChangeLogParser {
     private static final int GET_REVISION = 4;
     private static final int GET_PREVIOUS_REV = 5;
 
-// FIXME formatters are not thread-safe
-
     /** input format for dates read in from cvs log */
-    private static final SimpleDateFormat INPUT_DATE
+    private final SimpleDateFormat inputDate
         = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss", Locale.US);
     /**
      * New formatter used to parse CVS date/timestamp.
      */
-    private static final SimpleDateFormat CVS1129_INPUT_DATE =
+    private final SimpleDateFormat cvs1129InputDate =
         new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.US);
 
     static {
-        TimeZone utc = TimeZone.getTimeZone("UTC");
-        INPUT_DATE.setTimeZone(utc);
-        CVS1129_INPUT_DATE.setTimeZone(utc);
     }
 
     //The following is data used while processing stdout of CVS command
@@ -102,6 +97,10 @@ class ChangeLogParser {
         for (int i = 0; i < moduleNames.length; i++) {
             moduleNameLengths[i] = moduleNames[i].length();
         }
+
+        TimeZone utc = TimeZone.getTimeZone("UTC");
+        inputDate.setTimeZone(utc);
+        cvs1129InputDate.setTimeZone(utc);
     }
 
     /**
@@ -297,10 +296,10 @@ class ChangeLogParser {
      */
     private Date parseDate(final String date) {
         try {
-            return INPUT_DATE.parse(date);
+            return inputDate.parse(date);
         } catch (ParseException e) {
             try {
-                return CVS1129_INPUT_DATE.parse(date);
+                return cvs1129InputDate.parse(date);
             } catch (ParseException e2) {
                 throw new IllegalStateException("Invalid date format: " + date);
             }

http://git-wip-us.apache.org/repos/asf/ant/blob/8e56f57a/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java b/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java
index 2385e51..7e43f3a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriter.java
@@ -34,18 +34,18 @@ import org.w3c.dom.Element;
  */
 public class ChangeLogWriter {
     /** output format for dates written to xml file */
-    private static final SimpleDateFormat OUTPUT_DATE
+    private final SimpleDateFormat outputDate
         = new SimpleDateFormat("yyyy-MM-dd");
     /** output format for times written to xml file */
-    private static final SimpleDateFormat OUTPUT_TIME
+    private static SimpleDateFormat outputTime
         = new SimpleDateFormat("HH:mm");
     /** stateless helper for writing the XML document */
     private static final DOMElementWriter DOM_WRITER = new DOMElementWriter();
 
-    static {
+    public ChangeLogWriter() {
         TimeZone utc = TimeZone.getTimeZone("UTC");
-        OUTPUT_DATE.setTimeZone(utc);
-        OUTPUT_TIME.setTimeZone(utc);
+        outputDate.setTimeZone(utc);
+        outputTime.setTimeZone(utc);
     }
 
     /**
@@ -87,9 +87,9 @@ public class ChangeLogWriter {
                             final CVSEntry entry) throws IOException {
         Element ent = doc.createElement("entry");
         DOMUtils.appendTextElement(ent, "date",
-                                   OUTPUT_DATE.format(entry.getDate()));
+                                   outputDate.format(entry.getDate()));
         DOMUtils.appendTextElement(ent, "time",
-                                   OUTPUT_TIME.format(entry.getDate()));
+                                   outputTime.format(entry.getDate()));
         DOMUtils.appendCDATAElement(ent, "author", entry.getAuthor());
 
         final Enumeration enumeration = entry.getFiles().elements();