Skip to content

Commit

Permalink
Merge pull request orphan-oss#46 from kazuki43zoo/support-concurrent-…
Browse files Browse the repository at this point in the history
…on-DefaultClassResolver

Support concurrent on DefaultClassResolver

(cherry picked from commit 26f9c15)
  • Loading branch information
lukaszlenart authored and JCgH4164838Gh792C124B5 committed Sep 29, 2019
1 parent e4cc4d5 commit 19f8381
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions src/java/ognl/DefaultClassResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -41,28 +42,21 @@
*/
public class DefaultClassResolver extends Object implements ClassResolver
{
private Map classes = new HashMap(101);
private final Map<String, Class> 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;
}
}

0 comments on commit 19f8381

Please sign in to comment.