cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r1356579 - in /cxf/trunk: api/src/main/java/org/apache/cxf/common/util/ api/src/main/java/org/apache/cxf/configuration/spring/ api/src/main/java/org/apache/cxf/endpoint/ api/src/main/java/org/apache/cxf/helpers/ rt/core/src/main/java/org/ap...
Date Tue, 03 Jul 2012 06:34:47 GMT
Author: ffang
Date: Tue Jul  3 06:34:44 2012
New Revision: 1356579

URL: http://svn.apache.org/viewvc?rev=1356579&view=rev
Log:
[CXF-4404]potential atomicity violation issues because of misusing concurrent collections

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java
    cxf/trunk/api/src/main/java/org/apache/cxf/configuration/spring/AbstractSpringBeanMap.java
    cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
    cxf/trunk/api/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java
    cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/CXFExtensionBundleListener.java
    cxf/trunk/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
    cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
    cxf/trunk/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalTransportFactory.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java?rev=1356579&r1=1356578&r2=1356579&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/common/util/ASMHelper.java Tue Jul  3 06:34:44
2012
@@ -294,7 +294,7 @@ public class ASMHelper {
     }
     
     public static class TypeHelperClassLoader extends ClassLoader {
-        Map<String, Class<?>> defined = new ConcurrentHashMap<String, Class<?>>();
+        ConcurrentHashMap<String, Class<?>> defined = new ConcurrentHashMap<String,
Class<?>>();
         
         TypeHelperClassLoader(ClassLoader parent) {
             super(parent);
@@ -303,7 +303,7 @@ public class ASMHelper {
             return defined.get(name.replace('/', '.'));
         }
         
-        public synchronized Class<?> defineClass(String name, byte bytes[]) {
+        public Class<?> defineClass(String name, byte bytes[]) {
             Class<?> ret = defined.get(name.replace('/', '.'));
             if (ret != null) {
                 return ret;
@@ -323,7 +323,10 @@ public class ASMHelper {
             }
             
             ret = super.defineClass(name.replace('/', '.'), bytes, 0, bytes.length);
-            defined.put(name.replace('/', '.'), ret);
+            Class<?> tmpRet = defined.putIfAbsent(name.replace('/', '.'), ret);
+            if (tmpRet != null) {
+                ret = tmpRet;
+            }
             return ret;
         }
     }

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/configuration/spring/AbstractSpringBeanMap.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/configuration/spring/AbstractSpringBeanMap.java?rev=1356579&r1=1356578&r2=1356579&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/configuration/spring/AbstractSpringBeanMap.java
(original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/configuration/spring/AbstractSpringBeanMap.java
Tue Jul  3 06:34:44 2012
@@ -47,8 +47,8 @@ abstract class AbstractSpringBeanMap<X, 
     protected Class<?> type;
     protected String idsProperty;
     protected String staticFieldName;
-    protected Map<X, List<String>> idToBeanName = new ConcurrentHashMap<X,
List<String>>();
-    protected Map<X, V> putStore = new ConcurrentHashMap<X, V>(4, 0.75f, 4);
+    protected ConcurrentHashMap<X, List<String>> idToBeanName = new ConcurrentHashMap<X,
List<String>>();
+    protected ConcurrentHashMap<X, V> putStore = new ConcurrentHashMap<X, V>(4,
0.75f, 4);
 
     public void setApplicationContext(ApplicationContext ctx) throws BeansException {
         this.context = ctx;
@@ -64,11 +64,11 @@ abstract class AbstractSpringBeanMap<X, 
     
     protected abstract void processBeans(ApplicationContext beanFactory);
 
-    protected synchronized List<String> getBeanListForId(X id) {
-        List<String> lst = idToBeanName.get(id);
-        if (lst == null) {
-            lst = new CopyOnWriteArrayList<String>();
-            idToBeanName.put(id, lst);
+    protected List<String> getBeanListForId(X id) {
+        List<String> lst = new CopyOnWriteArrayList<String>();
+        List<String> tmpLst = idToBeanName.putIfAbsent(id, lst);
+        if (tmpLst != null) {
+            lst = tmpLst;
         }
         return lst;
     }
@@ -151,11 +151,11 @@ abstract class AbstractSpringBeanMap<X, 
             for (String name : names) {
                 context.getBean(name);
             }
-            if (putStore.containsKey(key)) {
-                return putStore.get(key);
-            }
             V v = (V)context.getBean(names.get(0));
-            putStore.put((X)key, v);
+            V tmpV = putStore.putIfAbsent((X)key, v);
+            if (tmpV != null) {
+                v = tmpV;
+            }
             idToBeanName.remove(key);
             return v;
         } else {

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java?rev=1356579&r1=1356578&r2=1356579&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ClientImpl.java Tue Jul  3 06:34:44
2012
@@ -299,8 +299,8 @@ public class ClientImpl
 
     }
     public boolean isThreadLocalRequestContext() {
-        if (currentRequestContext.containsKey(THREAD_LOCAL_REQUEST_CONTEXT)) {
-            Object o = currentRequestContext.get(THREAD_LOCAL_REQUEST_CONTEXT);
+        Object o = currentRequestContext.get(THREAD_LOCAL_REQUEST_CONTEXT);
+        if (o != null) {
             boolean local = false;
             if (o instanceof Boolean) {
                 local = ((Boolean)o).booleanValue();

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java?rev=1356579&r1=1356578&r2=1356579&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/helpers/HttpHeaderHelper.java Tue Jul  3 06:34:44
2012
@@ -43,7 +43,7 @@ public final class HttpHeaderHelper {
     private static final String ISO88591 = Charset.forName("ISO-8859-1").name();
     
     private static Map<String, String> internalHeaders = new HashMap<String, String>();
-    private static Map<String, String> encodings = new ConcurrentHashMap<String,
String>();
+    private static ConcurrentHashMap<String, String> encodings = new ConcurrentHashMap<String,
String>();
     
     static {
         internalHeaders.put("Accept-Encoding", "accept-encoding");
@@ -124,7 +124,10 @@ public final class HttpHeaderHelper {
             } catch (UnsupportedCharsetException uce) {
                 return null;
             }
-            encodings.put(enc, newenc);
+            String tmpenc = encodings.putIfAbsent(enc, newenc);
+            if (tmpenc != null) {
+                newenc = tmpenc;
+            }
         }
         return newenc;
     }

Modified: cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/CXFExtensionBundleListener.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/CXFExtensionBundleListener.java?rev=1356579&r1=1356578&r2=1356579&view=diff
==============================================================================
--- cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/CXFExtensionBundleListener.java
(original)
+++ cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/osgi/CXFExtensionBundleListener.java
Tue Jul  3 06:34:44 2012
@@ -90,7 +90,10 @@ public class CXFExtensionBundleListener 
         List<Extension> list = extensions.get(bundle.getBundleId());
         if (list == null) {
             list = new CopyOnWriteArrayList<Extension>();
-            extensions.put(bundle.getBundleId(), list);
+            List<Extension> preList = extensions.putIfAbsent(bundle.getBundleId(),
list);
+            if (preList != null) {
+                list = preList;
+            }
         }
         for (Extension ext : orig) {
             list.add(new OSGiExtension(ext, bundle));

Modified: cxf/trunk/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java?rev=1356579&r1=1356578&r2=1356579&view=diff
==============================================================================
--- cxf/trunk/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
(original)
+++ cxf/trunk/rt/features/clustering/src/main/java/org/apache/cxf/clustering/FailoverTargetSelector.java
Tue Jul  3 06:34:44 2012
@@ -48,7 +48,7 @@ public class FailoverTargetSelector exte
 
     private static final Logger LOG =
         LogUtils.getL7dLogger(FailoverTargetSelector.class);
-    protected Map<InvocationKey, InvocationContext> inProgress 
+    protected ConcurrentHashMap<InvocationKey, InvocationContext> inProgress 
         = new ConcurrentHashMap<InvocationKey, InvocationContext>();;
     protected FailoverStrategy failoverStrategy;
     
@@ -73,7 +73,7 @@ public class FailoverTargetSelector exte
      * 
      * @param message the current Message
      */
-    public synchronized void prepare(Message message) {
+    public void prepare(Message message) {
         Exchange exchange = message.getExchange();
         InvocationKey key = new InvocationKey(exchange);
         if (!inProgress.containsKey(key)) {
@@ -88,7 +88,7 @@ public class FailoverTargetSelector exte
                                       bindingOperationInfo,
                                       params,
                                       context);
-            inProgress.put(key, invocation);
+            inProgress.putIfAbsent(key, invocation);
         }
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=1356579&r1=1356578&r2=1356579&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
Tue Jul  3 06:34:44 2012
@@ -133,7 +133,10 @@ public class ClassResourceInfo extends A
             cri = ResourceUtils.createClassResourceInfo(typedClass, instanceClass, false,
enableStatic,
                                                         getBus());
             if (cri != null) {
-                subResources.putIfAbsent(key, cri);
+                ClassResourceInfo tmpCri = subResources.putIfAbsent(key, cri);
+                if (tmpCri != null) {
+                    cri = tmpCri;
+                }
             }
         }
         return cri;

Modified: cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java?rev=1356579&r1=1356578&r2=1356579&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
(original)
+++ cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/json/JSONProvider.java
Tue Jul  3 06:34:44 2012
@@ -401,8 +401,8 @@ public class JSONProvider<T> extends Abs
             }
             String prefix = "";
             if (!ignoreNamespaces) {
-                if (namespaceMap.containsKey(qname.getNamespaceURI())) {
-                    prefix = namespaceMap.get(qname.getNamespaceURI());
+                prefix = namespaceMap.get(qname.getNamespaceURI());
+                if (prefix != null) {
                     if (prefix.length() > 0) {
                         prefix += ".";
                     }
@@ -410,6 +410,7 @@ public class JSONProvider<T> extends Abs
                     prefix = "ns1.";
                 }
             }
+            prefix = (prefix == null) ? "" : prefix;
             startTag = "{\"" + prefix + qname.getLocalPart() + "\":[";
             endTag = "]}";
         } else if (serializeAsArray) {

Modified: cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java?rev=1356579&r1=1356578&r2=1356579&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
(original)
+++ cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
Tue Jul  3 06:34:44 2012
@@ -104,7 +104,7 @@ public class JettyHTTPServerEngineFactor
         setBus(b);
     }    
     
-    private static synchronized JettyHTTPServerEngine getOrCreate(JettyHTTPServerEngineFactory
factory,
+    private static JettyHTTPServerEngine getOrCreate(JettyHTTPServerEngineFactory factory,
                     String host,
                     int port,
                     TLSServerParameters tlsParams) throws IOException, GeneralSecurityException
{
@@ -115,8 +115,11 @@ public class JettyHTTPServerEngineFactor
             if (tlsParams != null) {
                 ref.setTlsServerParameters(tlsParams);
             }
-            portMap.put(port, ref);
+            JettyHTTPServerEngine tmpRef = portMap.putIfAbsent(port, ref);
             ref.finalizeConfig();
+            if (tmpRef != null) {
+                ref = tmpRef;
+            }
         }
         return ref;
     }

Modified: cxf/trunk/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalTransportFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalTransportFactory.java?rev=1356579&r1=1356578&r2=1356579&view=diff
==============================================================================
--- cxf/trunk/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalTransportFactory.java
(original)
+++ cxf/trunk/rt/transports/local/src/main/java/org/apache/cxf/transport/local/LocalTransportFactory.java
Tue Jul  3 06:34:44 2012
@@ -127,7 +127,10 @@ public class LocalTransportFactory exten
         d = destinations.get(addr);
         if (d == null) {
             d = createDestination(ei, reference);
-            destinations.put(addr, d);
+            Destination tmpD = destinations.putIfAbsent(addr, d);
+            if (tmpD != null) {
+                d = tmpD;
+            }
         }
         return d;
     }



Mime
View raw message