From 38f19ad4b77b0ef6c373696693e7c926973ea1ce Mon Sep 17 00:00:00 2001 From: Sean Mullan Date: Thu, 30 Oct 2008 17:24:08 -0400 Subject: [PATCH] 6764553: com.sun.org.apache.xml.internal.security.utils.IdResolver is not thread safe Reviewed-by: valeriep --- .../xml/internal/security/utils/IdResolver.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java index d7565157e49..da5c4960973 100644 --- a/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java +++ b/jdk/src/share/classes/com/sun/org/apache/xml/internal/security/utils/IdResolver.java @@ -70,10 +70,13 @@ public class IdResolver { */ 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 @@ public class IdResolver { 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) {