Skip to content

Commit d0a83f4

Browse files
committed
BeanComparator.compare(T, T) now throws IllegalArgumentException instead
of RuntimeException to wrap all cases of ReflectiveOperationException
1 parent e80b651 commit d0a83f4

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<body>
3131
<release version="1.10.2" date="YYYY-MM-DD" description="This is a maintenance release and requires Java 8.">
3232
<!-- FIX -->
33+
<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>
3334
<!-- ADD -->
3435
<!-- UPDATE -->
3536
</release>

src/main/java/org/apache/commons/beanutils/BeanComparator.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.commons.beanutils;
1919

2020
import java.io.Serializable;
21-
import java.lang.reflect.InvocationTargetException;
2221
import java.util.Comparator;
2322

2423
import org.apache.commons.collections.comparators.ComparableComparator;
@@ -122,7 +121,7 @@ public BeanComparator(final String property, final Comparator<?> comparator) {
122121
}
123122

124123
/**
125-
* Compare two JavaBeans by their shared property.
124+
* Compares two JavaBeans by their shared property.
126125
* If {@link #getProperty} is null then the actual objects will be compared.
127126
*
128127
* @param o1 Object The first bean to get data from to compare against
@@ -131,22 +130,16 @@ public BeanComparator(final String property, final Comparator<?> comparator) {
131130
*/
132131
@Override
133132
public int compare(final T o1, final T o2) {
134-
135133
if (property == null) {
136134
// compare the actual objects
137135
return internalCompare(o1, o2);
138136
}
139-
140137
try {
141138
final Object value1 = PropertyUtils.getProperty(o1, property);
142139
final Object value2 = PropertyUtils.getProperty(o2, property);
143140
return internalCompare(value1, value2);
144-
} catch (final IllegalAccessException iae) {
145-
throw new RuntimeException("IllegalAccessException: " + iae.toString());
146-
} catch (final InvocationTargetException ite) {
147-
throw new RuntimeException("InvocationTargetException: " + ite.toString());
148-
} catch (final NoSuchMethodException nsme) {
149-
throw new RuntimeException("NoSuchMethodException: " + nsme.toString());
141+
} catch (final ReflectiveOperationException e) {
142+
throw new IllegalArgumentException(e);
150143
}
151144
}
152145

0 commit comments

Comments
 (0)