Skip to content

Commit 7caf777

Browse files
committed
Remove org.apache.commons.beanutils2.MethodUtils.isAssignmentCompatible(Class
toClass, Class cls) in favor oforg.apache.commons.lang3.ClassUtils.isAssignable(Class cls, Class toClass)
1 parent e29a500 commit 7caf777

File tree

3 files changed

+5
-42
lines changed

3 files changed

+5
-42
lines changed

src/changes/changes.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
<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>
5050
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.toNonPrimitiveClass(Class) in favor of org.apache.commons.lang3.ClassUtils.primitiveToWrapper(Class).</action>
5151
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.getPrimitiveType(Class) in favor of org.apache.commons.lang3.ClassUtils.wrapperToPrimitive(Class).</action>
52-
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove unused org.apache.commons.beanutils2.MethodUtils.getPrimitiveWrapper(Class) in favor of org.apache.commons.lang3.ClassUtils.primitiveToWrapper(Class).</action>
52+
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove org.apache.commons.beanutils2.MethodUtils.getPrimitiveWrapper(Class) in favor of org.apache.commons.lang3.ClassUtils.primitiveToWrapper(Class).</action>
53+
<action dev="ggregory" type="remove" due-to="Gary Gregory">Remove org.apache.commons.beanutils2.MethodUtils.isAssignmentCompatible(Class toClass, Class cls) in favor oforg.apache.commons.lang3.ClassUtils.isAssignable(Class cls, Class toClass).</action>
5354
</release>
5455
<release version="2.0.0-M2" date="2025-05-25" description="This is a major release and requires Java 8.">
5556
<!-- FIX -->

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

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ public static Method getMatchingAccessibleMethod(final Class<?> clazz, final Str
443443
LOG.trace("Param=" + parameterTypes[n].getName());
444444
LOG.trace("Method=" + methodsParams[n].getName());
445445
}
446-
if (!isAssignmentCompatible(methodsParams[n], parameterTypes[n])) {
446+
if (!ClassUtils.isAssignable(parameterTypes[n], methodsParams[n])) {
447447
if (LOG.isTraceEnabled()) {
448448
LOG.trace(methodsParams[n] + " is not assignable from " + parameterTypes[n]);
449449
}
@@ -500,7 +500,8 @@ private static float getObjectTransformationCost(Class<?> srcClass, final Class<
500500
break;
501501
}
502502
}
503-
if (destClass.isInterface() && isAssignmentCompatible(destClass, srcClass)) {
503+
final Class<?> cls = srcClass;
504+
if (destClass.isInterface() && ClassUtils.isAssignable(cls, destClass)) {
504505
// slight penalty for interface match.
505506
// we still want an exact match to override an interface match, but
506507
// an interface match should override anything where we have to get a
@@ -688,42 +689,6 @@ public static Object invokeMethod(final Object object, final String methodName,
688689
return method.invoke(object, args);
689690
}
690691

691-
/**
692-
* <p>
693-
* Determine whether a type can be used as a parameter in a method invocation. This method handles primitive conversions correctly.
694-
* </p>
695-
*
696-
* <p>
697-
* In order words, it will match a {@code Boolean</code> to a <code>boolean},
698-
* a {@code Long</code> to a <code>long},
699-
* a {@code Float</code> to a <code>float},
700-
* a {@code Integer</code> to a <code>int},
701-
* and a {@code Double</code> to a <code>double}.
702-
* Now logic widening matches are allowed.
703-
* For example, a {@code Long</code> will not match a <code>int}.
704-
*
705-
* @param parameterType the type of parameter accepted by the method
706-
* @param parameterization the type of parameter being tested
707-
* @return true if the assignment is compatible.
708-
*/
709-
public static boolean isAssignmentCompatible(final Class<?> parameterType, final Class<?> parameterization) {
710-
// try plain assignment
711-
if (parameterType.isAssignableFrom(parameterization)) {
712-
return true;
713-
}
714-
715-
if (parameterType.isPrimitive()) {
716-
// this method does *not* do widening - you must specify exactly
717-
// is this the right behavior?
718-
final Class<?> parameterWrapperClazz = ClassUtils.wrapperToPrimitive(parameterType);
719-
if (parameterWrapperClazz != null) {
720-
return parameterWrapperClazz.equals(parameterization);
721-
}
722-
}
723-
724-
return false;
725-
}
726-
727692
/**
728693
* Sets whether methods should be cached for greater performance or not, default is {@code true}.
729694
*

src/test/java/org/apache/commons/beanutils2/bugs/Jira381Test.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,10 @@ public void performOp(final TestObject o) {
6767
*/
6868
@Test
6969
void testIssue_BEANUTILS_381_getMatchingAccessibleMethod() {
70-
7170
final Class<?> target = TestServiceBean.class;
7271
final String methodName = "performOp";
7372
final Class<?>[] runtimeClasses = { TestObjectSubclass.class };
74-
7573
final Method returned = MethodUtils.getMatchingAccessibleMethod(target, methodName, runtimeClasses);
76-
7774
assertEquals(target, returned.getDeclaringClass());
7875
assertEquals(methodName, returned.getName());
7976
assertEquals(TestObject.class, returned.getParameterTypes()[0]);

0 commit comments

Comments
 (0)