Skip to content

WW-4817 Similar to #36 for master #39

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

Merged
merged 1 commit into from
Aug 1, 2017
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
82 changes: 33 additions & 49 deletions src/java/ognl/OgnlRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -820,46 +820,15 @@ public static Object invokeMethod(Object target, Method method, Object[] argsArr
throws InvocationTargetException, IllegalAccessException
{
boolean syncInvoke = false;
boolean checkPermission = false;

// only synchronize method invocation if it actually requires it

synchronized(method) {
if (_methodAccessCache.get(method) == null
|| _methodAccessCache.get(method) == Boolean.TRUE) {
syncInvoke = true;
}

if (_securityManager != null && _methodPermCache.get(method) == null
|| _methodPermCache.get(method) == Boolean.FALSE) {
checkPermission = true;
}
}

Object result;
boolean wasAccessible = true;

if (syncInvoke)
{
synchronized(method)
{
if (checkPermission)
{
try
{
_securityManager.checkPermission(getPermission(method));
_methodPermCache.put(method, Boolean.TRUE);
} catch (SecurityException ex) {
_methodPermCache.put(method, Boolean.FALSE);
throw new IllegalAccessException("Method [" + method + "] cannot be accessed.");
}
}

if (_methodAccessCache.get(method) == null) {
if (!Modifier.isPublic(method.getModifiers()) || !Modifier.isPublic(method.getDeclaringClass().getModifiers()))
{
if (!(wasAccessible = ((AccessibleObject) method).isAccessible()))
if (!(((AccessibleObject) method).isAccessible()))
{
((AccessibleObject) method).setAccessible(true);
_methodAccessCache.put(method, Boolean.TRUE);
} else
{
Expand All @@ -869,28 +838,43 @@ public static Object invokeMethod(Object target, Method method, Object[] argsArr
{
_methodAccessCache.put(method, Boolean.FALSE);
}
}
if (_methodAccessCache.get(method) == Boolean.TRUE) {
syncInvoke = true;
}

result = method.invoke(target, argsArray);

if (!wasAccessible)
{
((AccessibleObject) method).setAccessible(false);
if (_methodPermCache.get(method) == null) {
if (_securityManager != null) {
try
{
_securityManager.checkPermission(getPermission(method));
_methodPermCache.put(method, Boolean.TRUE);
} catch (SecurityException ex) {
_methodPermCache.put(method, Boolean.FALSE);
throw new IllegalAccessException("Method [" + method + "] cannot be accessed.");
}
}
}
} else
{
if (checkPermission)
{
try
{
_securityManager.checkPermission(getPermission(method));
else {
_methodPermCache.put(method, Boolean.TRUE);
} catch (SecurityException ex) {
_methodPermCache.put(method, Boolean.FALSE);
throw new IllegalAccessException("Method [" + method + "] cannot be accessed.");
}
}
if (_methodPermCache.get(method) == Boolean.FALSE) {
throw new IllegalAccessException("Method [" + method + "] cannot be accessed.");
}
}

Object result;

if (syncInvoke) //if is not public and is not accessible
{
synchronized(method)
{
((AccessibleObject) method).setAccessible(true);
result = method.invoke(target, argsArray);
((AccessibleObject) method).setAccessible(false);
}
} else
{
result = method.invoke(target, argsArray);
}

Expand Down