Skip to content

Commit e14b4e1

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

File tree

3 files changed

+1
-70
lines changed

3 files changed

+1
-70
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<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>
4646
<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>
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>
48+
<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>
4849
</release>
4950
<release version="2.0.0-M2" date="2025-05-25" description="This is a major release and requires Java 8.">
5051
<!-- FIX -->

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

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -761,48 +761,6 @@ public static Object invokeMethod(final Object object, final String methodName,
761761
return method.invoke(object, args);
762762
}
763763

764-
/**
765-
* <p>
766-
* Invoke a named static method whose parameter type matches the object type.
767-
* </p>
768-
*
769-
* <p>
770-
* The behavior of this method is less deterministic than {@link #invokeExactMethod(Object object,String methodName,Object [] args)}. It loops through all
771-
* methods with names that match and then executes the first it finds with compatible parameters.
772-
* </p>
773-
*
774-
* <p>
775-
* This method supports calls to methods taking primitive parameters via passing in wrapping classes. So, for example, a {@code Boolean} class would match a
776-
* {@code boolean} primitive.
777-
* </p>
778-
*
779-
* <p>
780-
* This is a convenient wrapper for {@link #invokeStaticMethod(Class objectClass, String methodName, Object[] args, Class[] parameterTypes)}.
781-
* </p>
782-
*
783-
* @param objectClass invoke static method on this class
784-
* @param methodName get method with this name
785-
* @param args use these arguments - treat null as empty array (passing null will result in calling the parameterless method with name
786-
* {@code methodName}).
787-
* @return The value returned by the invoked method
788-
* @throws NoSuchMethodException if there is no such accessible method
789-
* @throws InvocationTargetException wraps an exception thrown by the method invoked
790-
* @throws IllegalAccessException if the requested method is not accessible via reflection
791-
* @since 1.8.0
792-
*/
793-
public static Object invokeStaticMethod(final Class<?> objectClass, final String methodName, Object[] args)
794-
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
795-
if (args == null) {
796-
args = BeanUtils.EMPTY_OBJECT_ARRAY;
797-
}
798-
final int arguments = args.length;
799-
final Class<?>[] parameterTypes = new Class[arguments];
800-
for (int i = 0; i < arguments; i++) {
801-
parameterTypes[i] = args[i].getClass();
802-
}
803-
return invokeStaticMethod(objectClass, methodName, args, parameterTypes);
804-
}
805-
806764
/**
807765
* <p>
808766
* Invoke a named static method whose parameter type matches the object type.

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -299,32 +299,4 @@ void testSimpleStatic3() throws Exception {
299299
assertInstanceOf(Integer.class, value, "currentCounter type");
300300
assertEquals(current, ((Integer) value).intValue(), "currentCounter value");
301301
}
302-
303-
@Test
304-
void testStaticInvokeMethod() throws Exception {
305-
306-
Object value;
307-
int current = TestBean.currentCounter();
308-
309-
value = MethodUtils.invokeStaticMethod(TestBean.class, "currentCounter", new Object[0]);
310-
assertEquals(current, ((Integer) value).intValue(), "currentCounter value");
311-
312-
MethodUtils.invokeStaticMethod(TestBean.class, "incrementCounter", new Object[0]);
313-
current++;
314-
315-
value = MethodUtils.invokeStaticMethod(TestBean.class, "currentCounter", new Object[0]);
316-
assertEquals(current, ((Integer) value).intValue(), "currentCounter value");
317-
318-
MethodUtils.invokeStaticMethod(TestBean.class, "incrementCounter", new Object[] { Integer.valueOf(8) });
319-
current += 8;
320-
321-
value = MethodUtils.invokeStaticMethod(TestBean.class, "currentCounter", new Object[0]);
322-
assertEquals(current, ((Integer) value).intValue(), "currentCounter value");
323-
324-
MethodUtils.invokeExactStaticMethod(TestBean.class, "incrementCounter", new Object[] { Integer.valueOf(8) }, new Class[] { Number.class });
325-
current += 16;
326-
327-
value = MethodUtils.invokeStaticMethod(TestBean.class, "currentCounter", new Object[0]);
328-
assertEquals(current, ((Integer) value).intValue(), "currentCounter value");
329-
}
330302
}

0 commit comments

Comments
 (0)