Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id CC367200AC5 for ; Sun, 5 Jun 2016 21:22:00 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id C5E54160A28; Sun, 5 Jun 2016 19:22:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1A389160A25 for ; Sun, 5 Jun 2016 21:21:59 +0200 (CEST) Received: (qmail 95330 invoked by uid 500); 5 Jun 2016 19:21:59 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 95319 invoked by uid 99); 5 Jun 2016 19:21:59 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Jun 2016 19:21:59 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 254E72C1F5C for ; Sun, 5 Jun 2016 19:21:59 +0000 (UTC) Date: Sun, 5 Jun 2016 19:21:59 +0000 (UTC) From: "Pascal Schumacher (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Resolved] (LANG-1195) Enhance MethodUtils to allow invocation of private methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Sun, 05 Jun 2016 19:22:01 -0000 [ https://issues.apache.org/jira/browse/LANG-1195?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Pascal Schumacher resolved LANG-1195. ------------------------------------- Resolution: Fixed Assignee: Pascal Schumacher Pull request merged. Thanks! > Enhance MethodUtils to allow invocation of private methods > ----------------------------------------------------------- > > Key: LANG-1195 > URL: https://issues.apache.org/jira/browse/LANG-1195 > Project: Commons Lang > Issue Type: Improvement > Components: lang.reflect.* > Environment: not environment specific > Reporter: Derek C. Ashmore > Assignee: Pascal Schumacher > Priority: Minor > Fix For: 3.5 > > > Currently, MethodUtils is restricted to finding and invoking accessible methods. Frequently, developers have a need to test 'private' methods. What I see is that they escalate access to 'protected' in order to more easily provide test coverage for these methods. From a design perspective, this is bad. > I propose to enhance MethodUtils so that it can easily invoke private methods. I'm not suggesting that developers should do this in production code, merely test code. Much as FieldUtils provides access to private fields via the 'forceAccess' overload on many of its methods. I've copied a utility like this around for years. It would be much more convenient to simply include it with Commons Lang. I propose adding the following overloads to existing methods on MethodUtils. > {code} > public static Object invokeMethod(final Object object, final boolean forceAccess, final String methodName) > throws NoSuchMethodException, IllegalAccessException, InvocationTargetException > > public static Object invokeMethod(final Object object, final boolean forceAccess, final String methodName, Object... args) > throws NoSuchMethodException, IllegalAccessException, InvocationTargetException > > public static Object invokeMethod(final Object object, final boolean forceAccess, final String methodName, Object[] args, Class[] parameterTypes) > throws NoSuchMethodException, IllegalAccessException, InvocationTargetException > {code} > Furthermore, I propose the following new method for finding private methods patterned after getAccessibleMatchingMethod: > {code} > public static Method getMatchingMethod(final Class cls, final String methodName, final Class... parameterTypes) > {code} > I have, in fact, forked your github repository and coded this enhancement as well as unit test coverage for this. I'll add a comment to this ticket once I get a branch in my fork created and the enhancement checked in. Every effort has been made to adhere to your coding conventions. Thanks for looking at this. -- This message was sent by Atlassian JIRA (v6.3.4#6332)