6764553: com.sun.org.apache.xml.internal.security.utils.IdResolver is not thread safe
authormullan
Thu, 30 Oct 2008 17:24:08 -0400
changeset 1515 86f91216664a
parent 1512 0f8eb7ad4ef5
child 1516 822b21150a7b
6764553: com.sun.org.apache.xml.internal.security.utils.IdResolver is not thread safe Reviewed-by: valeriep
jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java
--- a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java	Tue Oct 28 18:21:36 2008 +0100
+++ b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java	Thu Oct 30 17:24:08 2008 -0400
@@ -70,10 +70,13 @@
      */
     public static void registerElementById(Element element, String idValue) {
         Document doc = element.getOwnerDocument();
-        WeakHashMap elementMap = (WeakHashMap) docMap.get(doc);
-        if(elementMap == null) {
-            elementMap = new WeakHashMap();
-            docMap.put(doc, elementMap);
+        WeakHashMap elementMap;
+        synchronized (docMap) {
+            elementMap = (WeakHashMap) docMap.get(doc);
+            if (elementMap == null) {
+                elementMap = new WeakHashMap();
+                docMap.put(doc, elementMap);
+            }
         }
         elementMap.put(idValue, new WeakReference(element));
     }
@@ -153,7 +156,10 @@
     private static Element getElementByIdType(Document doc, String id) {
         if (log.isLoggable(java.util.logging.Level.FINE))
             log.log(java.util.logging.Level.FINE, "getElementByIdType() Search for ID " + id);
-        WeakHashMap elementMap = (WeakHashMap) docMap.get(doc);
+        WeakHashMap elementMap;
+        synchronized (docMap) {
+            elementMap = (WeakHashMap) docMap.get(doc);
+        }
         if (elementMap != null) {
             WeakReference weakReference = (WeakReference) elementMap.get(id);
             if (weakReference != null) {