diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java index 7a759c8c48..0e7a9b721f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/Attribute.java @@ -6,8 +6,8 @@ package net.sourceforge.pmd.lang.ast.xpath; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -20,7 +20,7 @@ public class Attribute { private static final Logger LOG = Logger.getLogger(Attribute.class.getName()); - private static final Map DETECTED_DEPRECATED_ATTRIBUTES = new ConcurrentHashMap<>(); + private static final ConcurrentMap DETECTED_DEPRECATED_ATTRIBUTES = new ConcurrentHashMap<>(); private static final Object[] EMPTY_OBJ_ARRAY = new Object[0]; @@ -48,14 +48,14 @@ public class Attribute { return value; } - if (method.isAnnotationPresent(Deprecated.class) && LOG.isLoggable(Level.WARNING) && !DETECTED_DEPRECATED_ATTRIBUTES.containsKey(getLoggableAttributeName())) { - DETECTED_DEPRECATED_ATTRIBUTES.put(getLoggableAttributeName(), Boolean.TRUE); + if (method.isAnnotationPresent(Deprecated.class) && LOG.isLoggable(Level.WARNING) + && DETECTED_DEPRECATED_ATTRIBUTES.putIfAbsent(getLoggableAttributeName(), Boolean.TRUE) == null) { LOG.warning("Use of deprecated attribute '" + getLoggableAttributeName() + "' in xpath query"); } // this lazy loading reduces calls to Method.invoke() by about 90% try { - return method.invoke(parent, EMPTY_OBJ_ARRAY); + return value = method.invoke(parent, EMPTY_OBJ_ARRAY); } catch (IllegalAccessException | InvocationTargetException iae) { iae.printStackTrace(); }