You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/08/16 20:47:01 UTC
(commons-beanutils) 04/06: 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
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
commit abb7745684c2150cac1c1d9a867e582f9cfdd1f3
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Aug 16 16:29:29 2025 -0400
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
---
src/changes/changes.xml | 1 +
.../org/apache/commons/beanutils2/MethodUtils.java | 41 ----------------------
.../apache/commons/beanutils2/MethodUtilsTest.java | 17 +++------
3 files changed, 6 insertions(+), 53 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index cdf324e3..df57474b 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,6 +46,7 @@
<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>
<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>
<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>
+ <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>
<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>
<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>
<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>
diff --git a/src/main/java/org/apache/commons/beanutils2/MethodUtils.java b/src/main/java/org/apache/commons/beanutils2/MethodUtils.java
index 7a5044f3..ed2fbe69 100644
--- a/src/main/java/org/apache/commons/beanutils2/MethodUtils.java
+++ b/src/main/java/org/apache/commons/beanutils2/MethodUtils.java
@@ -548,47 +548,6 @@ public final class MethodUtils {
return method.invoke(object, args);
}
- /**
- * Invoke a named method whose parameter type matches the object type.
- *
- * <p>
- * The behavior of this method is less deterministic than
- * {@link #invokeExactMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)}. It loops through all methods with names that match
- * and then executes the first it finds with compatible parameters.
- * </p>
- *
- * <p>
- * This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a {@code Boolean} class would match a
- * {@code boolean} primitive.
- * </p>
- *
- *
- * @param object invoke method on this object.
- * @param methodName get method with this name.
- * @param args use these arguments - treat null as empty array (passing null will result in calling the parameterless method with name
- * {@code methodName}).
- * @param parameterTypes match these parameters - treat null as empty array.
- * @return The value returned by the invoked method.
- * @throws NoSuchMethodException if there is no such accessible method.
- * @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, Object[] args, Class<?>[] parameterTypes)
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- if (parameterTypes == null) {
- parameterTypes = BeanUtils.EMPTY_CLASS_ARRAY;
- }
- if (args == null) {
- args = BeanUtils.EMPTY_OBJECT_ARRAY;
- }
-
- final Method method = getMatchingAccessibleMethod(object.getClass(), methodName, parameterTypes);
- if (method == null) {
- throw new NoSuchMethodException("No such accessible method: " + methodName + "() on object: " + object.getClass().getName());
- }
- return method.invoke(object, args);
- }
-
/**
* Sets whether methods should be cached for greater performance or not, default is {@code true}.
*
diff --git a/src/test/java/org/apache/commons/beanutils2/MethodUtilsTest.java b/src/test/java/org/apache/commons/beanutils2/MethodUtilsTest.java
index 9e572564..233dee49 100644
--- a/src/test/java/org/apache/commons/beanutils2/MethodUtilsTest.java
+++ b/src/test/java/org/apache/commons/beanutils2/MethodUtilsTest.java
@@ -106,13 +106,6 @@ class MethodUtilsTest {
assertEquals("parent", result);
}
- @Test
- void testInvokeMethodNullArrayNullArray() throws Exception {
- final Object result = MethodUtils.invokeMethod(new AlphaBean("parent"), "getName", null, null);
-
- assertEquals("parent", result);
- }
-
@Test
void testNoCaching() throws Exception {
// no caching
@@ -178,27 +171,27 @@ class MethodUtilsTest {
Object value = null;
int current = TestBean.currentCounter();
// Return initial value of the counter
- value = MethodUtils.invokeMethod(bean, "currentCounter", new Object[0], new Class[0]);
+ value = MethodUtils.invokeExactMethod(bean, "currentCounter", new Object[0], new Class[0]);
assertNotNull(value, "currentCounter exists");
assertInstanceOf(Integer.class, value, "currentCounter type");
assertEquals(current, ((Integer) value).intValue(), "currentCounter value");
// Increment via no-arguments version
- MethodUtils.invokeMethod(bean, "incrementCounter", new Object[0], new Class[0]);
+ MethodUtils.invokeExactMethod(bean, "incrementCounter", new Object[0], new Class[0]);
// Validate updated value
current++;
- value = MethodUtils.invokeMethod(bean, "currentCounter", new Object[0], new Class[0]);
+ value = MethodUtils.invokeExactMethod(bean, "currentCounter", new Object[0], new Class[0]);
assertNotNull(value, "currentCounter exists");
assertInstanceOf(Integer.class, value, "currentCounter type");
assertEquals(current, ((Integer) value).intValue(), "currentCounter value");
// Increment via specified-argument version
- MethodUtils.invokeMethod(bean, "incrementCounter", new Object[] { Integer.valueOf(5) }, new Class[] { Integer.TYPE });
+ MethodUtils.invokeExactMethod(bean, "incrementCounter", new Object[] { Integer.valueOf(5) }, new Class[] { Integer.TYPE });
// Validate updated value
current += 5;
- value = MethodUtils.invokeMethod(bean, "currentCounter", new Object[0], new Class[0]);
+ value = MethodUtils.invokeExactMethod(bean, "currentCounter", new Object[0], new Class[0]);
assertNotNull(value, "currentCounter exists");
assertInstanceOf(Integer.class, value, "currentCounter type");
assertEquals(current, ((Integer) value).intValue(), "currentCounter value");