Skip to content

Commit 7088280

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

File tree

3 files changed

+8
-67
lines changed

3 files changed

+8
-67
lines changed

src/changes/changes.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@
3737
<!-- UPDATE -->
3838
<action type="update" dev="ggregory" due-to="Gary Gregory, Dependabot">Bump org.apache.commons:commons-lang3 from 3.17.0 to 3.18.0 #357.</action>
3939
<!-- REMOVE -->
40-
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused ConstructorUtils in favor of Apache Commons Lang's ConstructorUtils. ConstructorUtils is unused in this component.</action>
41-
<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 MethodUtils.</action>
42-
<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 MethodUtils.</action>
43-
<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 MethodUtils.</action>
44-
<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 MethodUtils.</action>
45-
<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 MethodUtils.</action>
46-
<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 MethodUtils.</action>
40+
<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>
41+
<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.invokeStaticMethod(Class, String, Object) in favor of Apache Commons Lang's org.apache.commons.lang3.reflect.MethodUtils.</action>
43+
<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>
44+
<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>
45+
<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>
46+
<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>
47+
<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>
4748
</release>
4849
<release version="2.0.0-M2" date="2025-05-25" description="This is a major release and requires Java 8.">
4950
<!-- FIX -->

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

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -718,47 +718,6 @@ public static Object invokeExactStaticMethod(final Class<?> objectClass, final S
718718
return method.invoke(null, args);
719719
}
720720

721-
/**
722-
* <p>
723-
* Invoke a named method whose parameter type matches the object type.
724-
* </p>
725-
*
726-
* <p>
727-
* The behavior of this method is less deterministic than {@link #invokeExactMethod(Object object,String methodName,Object [] args)}. It loops through all
728-
* methods with names that match and then executes the first it finds with compatible parameters.
729-
* </p>
730-
*
731-
* <p>
732-
* This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a {@code Boolean} class would match a
733-
* {@code boolean} primitive.
734-
* </p>
735-
*
736-
* <p>
737-
* This is a convenient wrapper for {@link #invokeMethod(Object object, String methodName, Object[] args, Class[] parameterTypes)}.
738-
* </p>
739-
*
740-
* @param object invoke method on this object
741-
* @param methodName get method with this name
742-
* @param args use these arguments - treat null as empty array (passing null will result in calling the parameterless method with name
743-
* {@code methodName}).
744-
* @return The value returned by the invoked method
745-
* @throws NoSuchMethodException if there is no such accessible method
746-
* @throws InvocationTargetException wraps an exception thrown by the method invoked
747-
* @throws IllegalAccessException if the requested method is not accessible via reflection
748-
*/
749-
public static Object invokeMethod(final Object object, final String methodName, Object[] args)
750-
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
751-
if (args == null) {
752-
args = BeanUtils.EMPTY_OBJECT_ARRAY;
753-
}
754-
final int arguments = args.length;
755-
final Class<?>[] parameterTypes = new Class[arguments];
756-
for (int i = 0; i < arguments; i++) {
757-
parameterTypes[i] = args[i].getClass();
758-
}
759-
return invokeMethod(object, methodName, args, parameterTypes);
760-
}
761-
762721
/**
763722
* <p>
764723
* Invoke a named method whose parameter type matches the object type.

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

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,25 +112,6 @@ void testInvokeExactMethodNullArrayNullArray() throws Exception {
112112
assertEquals("parent", result);
113113
}
114114

115-
@Test
116-
void testInvokeMethodArray() throws Exception {
117-
final AbstractParent parent = new AlphaBean("parent");
118-
final AlphaBean childTwo = new AlphaBean("ChildTwo");
119-
120-
final Object[] params = new Object[2];
121-
params[0] = "parameter";
122-
params[1] = childTwo;
123-
124-
assertEquals("ChildTwo", MethodUtils.invokeMethod(parent, "testAddChild2", params), "Cannot invoke through abstract class");
125-
}
126-
127-
@Test
128-
void testInvokeMethodNullArray() throws Exception {
129-
final Object result = MethodUtils.invokeMethod(new AlphaBean("parent"), "getName", null);
130-
131-
assertEquals("parent", result);
132-
}
133-
134115
@Test
135116
void testInvokeMethodNullArrayNullArray() throws Exception {
136117
final Object result = MethodUtils.invokeMethod(new AlphaBean("parent"), "getName", null, null);

0 commit comments

Comments
 (0)