[
https://issues.apache.org/jira/browse/LANG-965?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15314244#comment-15314244
]
ASF GitHub Bot commented on LANG-965:
-------------------------------------
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?
> FieldUtils methods leak accessible flags
> ----------------------------------------
>
> Key: LANG-965
> URL: https://issues.apache.org/jira/browse/LANG-965
> Project: Commons Lang
> Issue Type: Bug
> Components: lang.reflect.*
> Affects Versions: 3.1, 3.2.1
> Environment: Apache Maven 3.1.1
> (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 11:22:22-0400)
> Maven home: C:\Java\apache-maven-3.1.1\bin\..
> Java version: 1.7.0_51, vendor: Oracle Corporation
> Java home: C:\Program Files\Java\jdk1.7.0_51\jre
> Default locale: en_US, platform encoding: Cp1252
> OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
> Reporter: Gary Gregory
> Assignee: Benedikt Ritter
> Fix For: Patch Needed
>
> Attachments: commons-lang-965.patch, commons-lang-965.patch
>
>
> When various FieldUtils methods are called the accessible is set to true but
> never reset to false. This is side-effect should be cleaned up.
> This makes a mess of the object model which represents the class meta data.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)