Skip to content

Commit abb7745

Browse files
committed
Remove unused
org.apache.commons.beanutils2.MethodUtils.invokeMethod(Object, String, Object[], Class[]) in favor of Apache Commons Lang's org.apache.commons.lang3.reflect.MethodUtils
1 parent 4fc13ec commit abb7745

File tree

3 files changed

+6
-53
lines changed

3 files changed

+6
-53
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
<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>
4747
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.invokeMethod(Object, String, Object) in favor of Apache Commons Lang's org.apache.commons.lang3.reflect.MethodUtils.</action>
4848
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.invokeMethod(Object, String, Object[]) in favor of Apache Commons Lang's org.apache.commons.lang3.reflect.MethodUtils.</action>
49+
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.invokeMethod(Object, String, Object[], Class[]) in favor of Apache Commons Lang's org.apache.commons.lang3.reflect.MethodUtils.</action>
4950
<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>
5051
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.invokeStaticMethod(Class, String, Object[], Class[]) in favor of Apache Commons Lang's org.apache.commons.lang3.reflect.MethodUtils.</action>
5152
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.invokeExactStaticMethod(Class, String, Object[], Class[]) 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 & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -548,47 +548,6 @@ public static Object invokeExactMethod(final Object object, final String methodN
548548
return method.invoke(object, args);
549549
}
550550

551-
/**
552-
* Invoke a named method whose parameter type matches the object type.
553-
*
554-
* <p>
555-
* The behavior of this method is less deterministic than
556-
* {@link #invokeExactMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)}. It loops through all methods with names that match
557-
* and then executes the first it finds with compatible parameters.
558-
* </p>
559-
*
560-
* <p>
561-
* This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a {@code Boolean} class would match a
562-
* {@code boolean} primitive.
563-
* </p>
564-
*
565-
*
566-
* @param object invoke method on this object.
567-
* @param methodName get method with this name.
568-
* @param args use these arguments - treat null as empty array (passing null will result in calling the parameterless method with name
569-
* {@code methodName}).
570-
* @param parameterTypes match these parameters - treat null as empty array.
571-
* @return The value returned by the invoked method.
572-
* @throws NoSuchMethodException if there is no such accessible method.
573-
* @throws InvocationTargetException wraps an exception thrown by the method invoked.
574-
* @throws IllegalAccessException if the requested method is not accessible via reflection.
575-
*/
576-
public static Object invokeMethod(final Object object, final String methodName, Object[] args, Class<?>[] parameterTypes)
577-
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
578-
if (parameterTypes == null) {
579-
parameterTypes = BeanUtils.EMPTY_CLASS_ARRAY;
580-
}
581-
if (args == null) {
582-
args = BeanUtils.EMPTY_OBJECT_ARRAY;
583-
}
584-
585-
final Method method = getMatchingAccessibleMethod(object.getClass(), methodName, parameterTypes);
586-
if (method == null) {
587-
throw new NoSuchMethodException("No such accessible method: " + methodName + "() on object: " + object.getClass().getName());
588-
}
589-
return method.invoke(object, args);
590-
}
591-
592551
/**
593552
* Sets whether methods should be cached for greater performance or not, default is {@code true}.
594553
*

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,6 @@ void testInvokeExactMethodNullArrayNullArray() throws Exception {
106106
assertEquals("parent", result);
107107
}
108108

109-
@Test
110-
void testInvokeMethodNullArrayNullArray() throws Exception {
111-
final Object result = MethodUtils.invokeMethod(new AlphaBean("parent"), "getName", null, null);
112-
113-
assertEquals("parent", result);
114-
}
115-
116109
@Test
117110
void testNoCaching() throws Exception {
118111
// no caching
@@ -178,27 +171,27 @@ void testSimpleStatic1() throws Exception {
178171
Object value = null;
179172
int current = TestBean.currentCounter();
180173
// Return initial value of the counter
181-
value = MethodUtils.invokeMethod(bean, "currentCounter", new Object[0], new Class[0]);
174+
value = MethodUtils.invokeExactMethod(bean, "currentCounter", new Object[0], new Class[0]);
182175
assertNotNull(value, "currentCounter exists");
183176
assertInstanceOf(Integer.class, value, "currentCounter type");
184177
assertEquals(current, ((Integer) value).intValue(), "currentCounter value");
185178

186179
// Increment via no-arguments version
187-
MethodUtils.invokeMethod(bean, "incrementCounter", new Object[0], new Class[0]);
180+
MethodUtils.invokeExactMethod(bean, "incrementCounter", new Object[0], new Class[0]);
188181

189182
// Validate updated value
190183
current++;
191-
value = MethodUtils.invokeMethod(bean, "currentCounter", new Object[0], new Class[0]);
184+
value = MethodUtils.invokeExactMethod(bean, "currentCounter", new Object[0], new Class[0]);
192185
assertNotNull(value, "currentCounter exists");
193186
assertInstanceOf(Integer.class, value, "currentCounter type");
194187
assertEquals(current, ((Integer) value).intValue(), "currentCounter value");
195188

196189
// Increment via specified-argument version
197-
MethodUtils.invokeMethod(bean, "incrementCounter", new Object[] { Integer.valueOf(5) }, new Class[] { Integer.TYPE });
190+
MethodUtils.invokeExactMethod(bean, "incrementCounter", new Object[] { Integer.valueOf(5) }, new Class[] { Integer.TYPE });
198191

199192
// Validate updated value
200193
current += 5;
201-
value = MethodUtils.invokeMethod(bean, "currentCounter", new Object[0], new Class[0]);
194+
value = MethodUtils.invokeExactMethod(bean, "currentCounter", new Object[0], new Class[0]);
202195
assertNotNull(value, "currentCounter exists");
203196
assertInstanceOf(Integer.class, value, "currentCounter type");
204197
assertEquals(current, ((Integer) value).intValue(), "currentCounter value");

0 commit comments

Comments
 (0)