Fixed concurency bug when multiple threads tried to compute package name. 33/5233/5
authorTony Tkacik <ttkacik@cisco.com>
Mon, 10 Feb 2014 19:11:15 +0000 (20:11 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 14 Feb 2014 08:26:30 +0000 (08:26 +0000)
Change-Id: Ifed593dc386124a596cc85e6aea512360a9d942b
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/BindingGeneratorUtil.java

index e39d6251eaaa3e0953d4b6d29d2d4bdd1a367e6c..0bb19794179dcf8fdb90c7b7ac1d8ae0bb8ccb44 100644 (file)
@@ -12,7 +12,6 @@ import java.io.DataOutputStream;
 import java.io.IOException;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
-import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -50,7 +49,18 @@ import org.opendaylight.yangtools.yang.model.util.ExtendedType;
  */
 public final class BindingGeneratorUtil {
 
-    private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyMMdd");
+    private static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = new ThreadLocal<SimpleDateFormat>() {
+
+        @Override
+        protected SimpleDateFormat initialValue() {
+            return new SimpleDateFormat("yyMMdd");
+        }
+
+        @Override
+        public void set(SimpleDateFormat value) {
+            throw new UnsupportedOperationException();
+        }
+    };
 
     /**
      * Array of strings values which represents JAVA reserved words.
@@ -172,7 +182,7 @@ public final class BindingGeneratorUtil {
 
         packageNameBuilder.append(namespace);
         packageNameBuilder.append(".rev");
-        packageNameBuilder.append(DATE_FORMAT.format(module.getRevision()));
+        packageNameBuilder.append(DATE_FORMAT.get().format(module.getRevision()));
 
         return validateJavaPackage(packageNameBuilder.toString());
     }
@@ -253,7 +263,7 @@ public final class BindingGeneratorUtil {
      *            JAVA class name
      * @return string which is in accordance with best practices for JAVA class
      *         name.
-     *         
+     *
      * @deprecated Use {@link BindingMapping#getClassName(QName)} instead.
      */
     @Deprecated