Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support concurrent on DefaultClassResolver #46

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions src/main/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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do prefer pure if clause but that's ok :)

classes.put(className, result);
return result;
}
}