Github user PascalSchumacher commented on a diff in the pull request:

    https://github.com/apache/commons-lang/pull/141#discussion_r65721245
  
    --- Diff: src/main/java/org/apache/commons/lang3/reflect/MethodUtils.java 
---
    @@ -142,21 +193,57 @@ public static Object invokeMethod(final Object 
object, final String methodName,
          * @throws InvocationTargetException wraps an exception thrown by the 
method invoked
          * @throws IllegalAccessException if the requested method is not 
accessible via reflection
          */
    -    public static Object invokeMethod(final Object object, final String 
methodName,
    +    public static Object invokeMethod(final Object object, final boolean 
forceAccess, final String methodName,
                 Object[] args, Class<?>[] parameterTypes)
                 throws NoSuchMethodException, IllegalAccessException,
                 InvocationTargetException {
             parameterTypes = ArrayUtils.nullToEmpty(parameterTypes);
             args = ArrayUtils.nullToEmpty(args);
    -        final Method method = 
getMatchingAccessibleMethod(object.getClass(),
    -                methodName, parameterTypes);
    +        
    +        final String messagePrefix;
    +        final Method method;
    +        if (forceAccess) {
    +            messagePrefix = "No such method: ";
    +            method = getMatchingMethod(object.getClass(), methodName, 
parameterTypes);
    +            if (method != null) {
    +                method.setAccessible(true);
    --- End diff --
    
    For `FieldUtils` there is this jira issue: 
https://issues.apache.org/jira/browse/LANG-965?jql=project%20%3D%20LANG%20AND%20status%20%3D%20Open%20ORDER%20BY%20priority%20DESC
 "FieldUtils methods leak accessible flags" with requests that the visibility 
of a field should be restored after the field is written. Maybe the visibility 
of the method should also be restored after it is invoked? What do think? 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to