From 19f8381430702875f2674d2b20366422b177ab8b Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Mon, 19 Mar 2018 15:03:09 +0100 Subject: [PATCH] Merge pull request #46 from kazuki43zoo/support-concurrent-on-DefaultClassResolver Support concurrent on DefaultClassResolver (cherry picked from commit 26f9c155fda638ce66bb5de50ee8f44342b3ab71) --- src/java/ognl/DefaultClassResolver.java | 32 ++++++++++--------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/src/java/ognl/DefaultClassResolver.java b/src/java/ognl/DefaultClassResolver.java index a103877b..1d0c08e0 100644 --- a/src/java/ognl/DefaultClassResolver.java +++ b/src/java/ognl/DefaultClassResolver.java @@ -30,7 +30,8 @@ //-------------------------------------------------------------------------- package ognl; -import java.util.*; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; /** * Default class resolution. Uses Class.forName() to look up classes by name. @@ -41,28 +42,21 @@ */ public class DefaultClassResolver extends Object implements ClassResolver { - private Map classes = new HashMap(101); + private final Map classes = new ConcurrentHashMap<>(101); public DefaultClassResolver() { super(); } - public Class classForName(String className, Map context) throws ClassNotFoundException - { - Class result = null; - - if ((result = (Class)classes.get(className)) == null) { - try { - result = Class.forName(className); - } catch (ClassNotFoundException ex) { - if (className.indexOf('.') == -1) { - result = Class.forName("java.lang." + className); - classes.put("java.lang." + className, result); - } - } - classes.put(className, result); - } - return result; - } + public Class classForName(String className, Map context) throws ClassNotFoundException + { + Class result = classes.get(className); + if (result != null) { + return result; + } + result = (className.indexOf('.') == -1) ? Class.forName("java.lang." + className) : Class.forName(className); + classes.put(className, result); + return result; + } }