jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1459908 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
Date Fri, 22 Mar 2013 17:35:36 GMT
Author: mduerig
Date: Fri Mar 22 17:35:36 2013
New Revision: 1459908

URL: http://svn.apache.org/r1459908
Log:
OAK-714: Potential unsynchronised concurrent access to name space map in LocalNameMapper
synchronize access to name space map

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java?rev=1459908&r1=1459907&r2=1459908&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
Fri Mar 22 17:35:36 2013
@@ -16,12 +16,13 @@
  */
 package org.apache.jackrabbit.oak.namepath;
 
-import java.util.Map;
-import javax.annotation.CheckForNull;
-
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 
+import java.util.Map;
+
+import javax.annotation.CheckForNull;
+
 /**
  * Name mapper with local namespace mappings.
  */
@@ -49,25 +50,27 @@ public abstract class LocalNameMapper ex
                             "No namespace mapping found for " + oakName);
                 }
 
-                for (Map.Entry<String, String> entry : local.entrySet()) {
-                    if (uri.equals(entry.getValue())) {
-                        String jcrPrefix = entry.getKey();
-                        if (jcrPrefix.equals(oakPrefix)) {
-                            return oakName;
-                        } else {
-                            return jcrPrefix + oakName.substring(colon);
+                synchronized (local) {
+                    for (Map.Entry<String, String> entry : local.entrySet()) {
+                        if (uri.equals(entry.getValue())) {
+                            String jcrPrefix = entry.getKey();
+                            if (jcrPrefix.equals(oakPrefix)) {
+                                return oakName;
+                            } else {
+                                return jcrPrefix + oakName.substring(colon);
+                            }
                         }
                     }
-                }
 
-                // local mapping not found for this URI, make sure there
-                // is no conflicting local mapping for the prefix
-                if (local.containsKey(oakPrefix)) {
-                    for (int i = 2; true; i++) {
-                        String jcrPrefix = oakPrefix + i;
-                        if (!local.containsKey(jcrPrefix)) {
-                            local.put(jcrPrefix, uri);
-                            return jcrPrefix + oakName.substring(colon);
+                    // local mapping not found for this URI, make sure there
+                    // is no conflicting local mapping for the prefix
+                    if (local.containsKey(oakPrefix)) {
+                        for (int i = 2; true; i++) {
+                            String jcrPrefix = oakPrefix + i;
+                            if (!local.containsKey(jcrPrefix)) {
+                                local.put(jcrPrefix, uri);
+                                return jcrPrefix + oakName.substring(colon);
+                            }
                         }
                     }
                 }
@@ -88,23 +91,25 @@ public abstract class LocalNameMapper ex
         if (hasSessionLocalMappings()) {
             int colon = jcrName.indexOf(':');
             if (colon > 0) {
-                String jcrPrefix = jcrName.substring(0, colon);
-                String uri = local.get(jcrPrefix);
-                if (uri != null) {
-                    String oakPrefix = getOakPrefixOrNull(uri);
-                    if (jcrPrefix.equals(oakPrefix)) {
-                        return jcrName;
-                    } else if (oakPrefix != null) {
-                        return oakPrefix + jcrName.substring(colon);
-                    } else {
-                        return null;
+                synchronized (local) {
+                    String jcrPrefix = jcrName.substring(0, colon);
+                    String uri = local.get(jcrPrefix);
+                    if (uri != null) {
+                        String oakPrefix = getOakPrefixOrNull(uri);
+                        if (jcrPrefix.equals(oakPrefix)) {
+                            return jcrName;
+                        } else if (oakPrefix != null) {
+                            return oakPrefix + jcrName.substring(colon);
+                        } else {
+                            return null;
+                        }
                     }
-                }
 
-                // Check that a global mapping is present and not remapped
-                uri = getNamespaceMap().get(jcrPrefix);
-                if (uri == null || local.values().contains(uri)) {
-                    return null;
+                    // Check that a global mapping is present and not remapped
+                    uri = getNamespaceMap().get(jcrPrefix);
+                    if (uri == null || local.values().contains(uri)) {
+                        return null;
+                    }
                 }
             }
         }
@@ -114,7 +119,9 @@ public abstract class LocalNameMapper ex
 
     @Override
     public boolean hasSessionLocalMappings() {
-        return !local.isEmpty();
+        synchronized (local) {
+            return !local.isEmpty();
+        }
     }
 
 }



Mime
View raw message