This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch 1.X in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git
commit d0a83f47104cddf876131b32d3c50894ec9c0b4c Author: Gary D. Gregory <garydgreg...@gmail.com> AuthorDate: Mon Apr 28 15:32:40 2025 -0400 BeanComparator.compare(T, T) now throws IllegalArgumentException instead of RuntimeException to wrap all cases of ReflectiveOperationException --- src/changes/changes.xml | 1 + .../java/org/apache/commons/beanutils/BeanComparator.java | 13 +++---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/changes/changes.xml b/src/changes/changes.xml index e9e7d99d..6b01d13d 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -30,6 +30,7 @@ <body> <release version="1.10.2" date="YYYY-MM-DD" description="This is a maintenance release and requires Java 8."> <!-- FIX --> + <action type="fix" dev="ggregory" due-to="Gary Gregory">BeanComparator.compare(T, T) now throws IllegalArgumentException instead of RuntimeException to wrap all cases of ReflectiveOperationException.</action> <!-- ADD --> <!-- UPDATE --> </release> diff --git a/src/main/java/org/apache/commons/beanutils/BeanComparator.java b/src/main/java/org/apache/commons/beanutils/BeanComparator.java index e45aa145..f65f6cb7 100644 --- a/src/main/java/org/apache/commons/beanutils/BeanComparator.java +++ b/src/main/java/org/apache/commons/beanutils/BeanComparator.java @@ -18,7 +18,6 @@ package org.apache.commons.beanutils; import java.io.Serializable; -import java.lang.reflect.InvocationTargetException; import java.util.Comparator; import org.apache.commons.collections.comparators.ComparableComparator; @@ -122,7 +121,7 @@ public class BeanComparator<T> implements Comparator<T>, Serializable { } /** - * Compare two JavaBeans by their shared property. + * Compares two JavaBeans by their shared property. * If {@link #getProperty} is null then the actual objects will be compared. * * @param o1 Object The first bean to get data from to compare against @@ -131,22 +130,16 @@ public class BeanComparator<T> implements Comparator<T>, Serializable { */ @Override public int compare(final T o1, final T o2) { - if (property == null) { // compare the actual objects return internalCompare(o1, o2); } - try { final Object value1 = PropertyUtils.getProperty(o1, property); final Object value2 = PropertyUtils.getProperty(o2, property); return internalCompare(value1, value2); - } catch (final IllegalAccessException iae) { - throw new RuntimeException("IllegalAccessException: " + iae.toString()); - } catch (final InvocationTargetException ite) { - throw new RuntimeException("InvocationTargetException: " + ite.toString()); - } catch (final NoSuchMethodException nsme) { - throw new RuntimeException("NoSuchMethodException: " + nsme.toString()); + } catch (final ReflectiveOperationException e) { + throw new IllegalArgumentException(e); } }