From 49e3de4a06394e6c1343bfda72324165438b03a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Mon, 14 Nov 2016 00:08:56 -0300 Subject: [PATCH] Allow concurrency in AttributeAxisIterator --- .../pmd/lang/ast/xpath/AttributeAxisIterator.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIterator.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIterator.java index beb15161f9..bec48ccb2c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIterator.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/AttributeAxisIterator.java @@ -5,11 +5,10 @@ package net.sourceforge.pmd.lang.ast.xpath; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import net.sourceforge.pmd.lang.ast.Node; @@ -49,8 +48,8 @@ public class AttributeAxisIterator implements Iterator { private int position; private Node node; - private static Map, MethodWrapper[]> methodCache = - Collections.synchronizedMap(new HashMap, MethodWrapper[]>()); + private static ConcurrentMap, MethodWrapper[]> methodCache = + new ConcurrentHashMap, MethodWrapper[]>(); public AttributeAxisIterator(Node contextNode) { this.node = contextNode; @@ -62,7 +61,7 @@ public class AttributeAxisIterator implements Iterator { postFilter.add(new MethodWrapper(element)); } } - methodCache.put(contextNode.getClass(), postFilter.toArray(new MethodWrapper[postFilter.size()])); + methodCache.putIfAbsent(contextNode.getClass(), postFilter.toArray(new MethodWrapper[postFilter.size()])); } this.methodWrappers = methodCache.get(contextNode.getClass());