Skip to content

Commit 482fc82

Browse files
committed
Remove unused
org.apache.commons.beanutils2.MethodUtils.invokeExactMethod(Object, String, Object[]) in favor of Apache Commons Lang's org.apache.commons.lang3.reflect.MethodUtils
1 parent 58358c7 commit 482fc82

File tree

4 files changed

+7
-42
lines changed

4 files changed

+7
-42
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
<!-- REMOVE -->
4040
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused ConstructorUtils in favor of Apache Commons Lang's org.apache.commons.lang3.ConstructorUtils. ConstructorUtils is unused in this component.</action>
4141
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.invokeExactMethod(Object, String, Object) in favor of Apache Commons Lang's org.apache.commons.lang3.reflect.MethodUtils.</action>
42+
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.invokeExactMethod(Object, String, Object[]) in favor of Apache Commons Lang's org.apache.commons.lang3.reflect.MethodUtils.</action>
4243
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.invokeStaticMethod(Class, String, Object) in favor of Apache Commons Lang's org.apache.commons.lang3.reflect.MethodUtils.</action>
4344
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.invokeExactStaticMethod(Class, String, Object) in favor of Apache Commons Lang's org.apache.commons.lang3.reflect.MethodUtils.</action>
4445
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.invokeExactStaticMethod(Class, String, Object) in favor of Apache Commons Lang's org.apache.commons.lang3.reflect.MethodUtils.</action>

src/main/java/org/apache/commons/beanutils2/MethodUtils.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -517,35 +517,6 @@ private static float getTotalTransformationCost(final Class<?>[] srcArgs, final
517517
return totalCost;
518518
}
519519

520-
/**
521-
* Invoke a method whose parameter types match exactly the object types.
522-
*
523-
* <p>
524-
* This uses reflection to invoke the method obtained from a call to {@code getAccessibleMethod()}.
525-
* </p>
526-
*
527-
* @param object invoke method on this object.
528-
* @param methodName get method with this name.
529-
* @param args use these arguments - treat null as empty array (passing null will result in calling the parameterless method with name
530-
* {@code methodName}).
531-
* @return The value returned by the invoked method.
532-
* @throws NoSuchMethodException if there is no such accessible method.
533-
* @throws InvocationTargetException wraps an exception thrown by the method invoked.
534-
* @throws IllegalAccessException if the requested method is not accessible via reflection.
535-
*/
536-
public static Object invokeExactMethod(final Object object, final String methodName, Object... args)
537-
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
538-
if (args == null) {
539-
args = BeanUtils.EMPTY_OBJECT_ARRAY;
540-
}
541-
final int arguments = args.length;
542-
final Class<?>[] parameterTypes = new Class[arguments];
543-
for (int i = 0; i < arguments; i++) {
544-
parameterTypes[i] = args[i].getClass();
545-
}
546-
return invokeExactMethod(object, methodName, args, parameterTypes);
547-
}
548-
549520
/**
550521
* Invoke a method whose parameter types match exactly the parameter types given.
551522
*

src/test/java/org/apache/commons/beanutils2/MethodUtilsTest.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void tearDown() {
6464
void testClearCache() throws Exception {
6565
MethodUtils.clearCache(); // make sure it starts empty
6666
final PublicSubBean bean = new PublicSubBean();
67-
MethodUtils.invokeExactMethod(bean, "setFoo", "alpha");
67+
MethodUtils.invokeExactMethod(bean, "setFoo", new String[] { "alpha" }, new Class[] { String.class });
6868
assertEquals(1, MethodUtils.clearCache());
6969
assertEquals(0, MethodUtils.clearCache());
7070
}
@@ -99,12 +99,6 @@ void testGetAccessibleMethodIndirectInterface() {
9999
assertMethod(method, "methodBaz");
100100
}
101101

102-
@Test
103-
void testInvokeExactMethodNullArray() throws Exception {
104-
final Object result = MethodUtils.invokeExactMethod(new AlphaBean("parent"), "getName", null);
105-
assertEquals("parent", result);
106-
}
107-
108102
@Test
109103
void testInvokeExactMethodNullArrayNullArray() throws Exception {
110104
final Object result = MethodUtils.invokeExactMethod(new AlphaBean("parent"), "getName", null, null);
@@ -125,7 +119,7 @@ void testNoCaching() throws Exception {
125119
MethodUtils.setCacheMethods(false);
126120

127121
final PublicSubBean bean = new PublicSubBean();
128-
MethodUtils.invokeExactMethod(bean, "setFoo", "alpha");
122+
MethodUtils.invokeExactMethod(bean, "setFoo", new String[] { "alpha" }, new Class[] { String.class });
129123
assertEquals(0, MethodUtils.clearCache());
130124

131125
// reset default
@@ -145,9 +139,9 @@ void testPublicSub() throws Exception {
145139

146140
// see if we can access public methods in a default access superclass
147141
// from a public access subclass instance
148-
MethodUtils.invokeExactMethod(bean, "setFoo", "alpha");
142+
MethodUtils.invokeExactMethod(bean, "setFoo", new String[] { "alpha" }, new Class[] { String.class });
149143
assertEquals(bean.getFoo(), "alpha", "Set value (foo:2)");
150-
MethodUtils.invokeExactMethod(bean, "setBar", "beta");
144+
MethodUtils.invokeExactMethod(bean, "setBar", new String[] { "beta" }, new Class[] { String.class });
151145
assertEquals(bean.getBar(), "beta", "Set value (bar:2)");
152146

153147
Method method = MethodUtils.getAccessibleMethod(PublicSubBean.class, "setFoo", String.class);
@@ -169,9 +163,8 @@ void testPublicSub() throws Exception {
169163
void testSetCacheMethods() throws Exception {
170164
MethodUtils.setCacheMethods(true);
171165
MethodUtils.clearCache(); // make sure it starts empty
172-
173166
final PublicSubBean bean = new PublicSubBean();
174-
MethodUtils.invokeExactMethod(bean, "setFoo", "alpha");
167+
MethodUtils.invokeExactMethod(bean, "setFoo", new String[] { "alpha" }, new Class[] { String.class });
175168
assertEquals(1, MethodUtils.clearCache());
176169
assertEquals(0, MethodUtils.clearCache());
177170
}

src/test/java/org/apache/commons/beanutils2/memoryleaktests/MemoryLeakTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ void testMethodUtils_cache_memoryLeak() throws Exception {
382382

383383
// if you comment the following line, the test will work, and the ClassLoader will be released.
384384
// That proves that nothing is wrong with the test, and MethodUtils is holding a reference
385-
assertEquals("initialValue", MethodUtils.invokeExactMethod(bean, "getName", new Object[0]));
385+
assertEquals("initialValue", MethodUtils.invokeExactMethod(bean, "getName", new Object[0], new Class[0]));
386386

387387
// this should make the reference go away.
388388
loader = null;

0 commit comments

Comments
 (0)