Reviewers: unnurg, jtamplin,

Message:
I've grep'ed in all com.google.web.bindery and didn't find any other
instance.
I also quickly looked into com.google.gwt in case there could have been
similar issues with GWT-RPC or some "shared" code, but didn't find
anything either.

Description:
Synchronize static Maps used for caching.


Please review this at https://gwt-code-reviews.appspot.com/1829804/

Affected files:
M user/src/com/google/web/bindery/autobean/shared/impl/AutoBeanCodexImpl.java


Index: user/src/com/google/web/bindery/autobean/shared/impl/AutoBeanCodexImpl.java diff --git a/user/src/com/google/web/bindery/autobean/shared/impl/AutoBeanCodexImpl.java b/user/src/com/google/web/bindery/autobean/shared/impl/AutoBeanCodexImpl.java index 78b4f2e4eed6fa6363e9584eb9d76bc54606f11e..5170f2bb208c2923e415e749cb14222f8b35f1ef 100644 --- a/user/src/com/google/web/bindery/autobean/shared/impl/AutoBeanCodexImpl.java +++ b/user/src/com/google/web/bindery/autobean/shared/impl/AutoBeanCodexImpl.java
@@ -515,16 +515,18 @@ public class AutoBeanCodexImpl {
   }

   public static Coder doCoderFor(AutoBean<?> bean, String propertyName) {
-    String key = key(bean, propertyName);
-    Coder toReturn = coderFor.get(key);
-    if (toReturn == null) {
-      bean.accept(new PropertyCoderCreator());
-      toReturn = coderFor.get(key);
+    synchronized (coderFor) {
+      String key = key(bean, propertyName);
+      Coder toReturn = coderFor.get(key);
       if (toReturn == null) {
-        throw new IllegalArgumentException(propertyName);
+        bean.accept(new PropertyCoderCreator());
+        toReturn = coderFor.get(key);
+        if (toReturn == null) {
+          throw new IllegalArgumentException(propertyName);
+        }
       }
+      return toReturn;
     }
-    return toReturn;
   }

public static <T> AutoBean<T> doDecode(EncodeState state, Class<T> clazz, Splittable data) {
@@ -562,12 +564,14 @@ public class AutoBeanCodexImpl {
   }

   public static <E extends Enum<?>> Coder enumCoder(Class<E> type) {
-    Coder toReturn = coders.get(type);
-    if (toReturn == null) {
-      toReturn = new EnumCoder<E>(type);
-      coders.put(type, toReturn);
+    synchronized (coders) {
+      Coder toReturn = coders.get(type);
+      if (toReturn == null) {
+        toReturn = new EnumCoder<E>(type);
+        coders.put(type, toReturn);
+      }
+      return toReturn;
     }
-    return toReturn;
   }

   public static Coder mapCoder(Coder valueCoder, Coder keyCoder) {
@@ -575,12 +579,14 @@ public class AutoBeanCodexImpl {
   }

   public static Coder objectCoder(Class<?> type) {
-    Coder toReturn = coders.get(type);
-    if (toReturn == null) {
-      toReturn = new ObjectCoder(type);
-      coders.put(type, toReturn);
+    synchronized (coders) {
+      Coder toReturn = coders.get(type);
+      if (toReturn == null) {
+        toReturn = new ObjectCoder(type);
+        coders.put(type, toReturn);
+      }
+      return toReturn;
     }
-    return toReturn;
   }

   public static Coder splittableCoder() {
@@ -588,12 +594,14 @@ public class AutoBeanCodexImpl {
   }

   public static Coder valueCoder(Class<?> type) {
-    Coder toReturn = coders.get(type);
-    if (toReturn == null) {
-      toReturn = new ValueCoder(type);
-      coders.put(type, toReturn);
+    synchronized (coders) {
+      Coder toReturn = coders.get(type);
+      if (toReturn == null) {
+        toReturn = new ValueCoder(type);
+        coders.put(type, toReturn);
+      }
+      return toReturn;
     }
-    return toReturn;
   }

   static Splittable tryExtractSplittable(Object value) {


--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to