You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/04/28 20:17:05 UTC

(commons-beanutils) branch 1.X updated (e80b651c -> 54696927)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch 1.X
in repository https://gitbox.apache.org/repos/asf/commons-beanutils.git


    from e80b651c Revert "Javadoc"
     new d0a83f47 BeanComparator.compare(T, T) now throws IllegalArgumentException instead of RuntimeException to wrap all cases of ReflectiveOperationException
     new 8bb5e61b Use Objects.requireNonNull()
     new b1f5abce MappedMethodReference.get() now throws IllegalStateException instead of RuntimeException to wrap cases of NoSuchMethodException
     new 54696927 ResultSetIterator.get(String) now throws IllegalArgumentException instead of RuntimeException to wrap cases of SQLException

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                                     |  6 ++++++
 .../java/org/apache/commons/beanutils/BeanComparator.java   | 13 +++----------
 .../apache/commons/beanutils/MappedPropertyDescriptor.java  | 11 +++++------
 .../org/apache/commons/beanutils/ResultSetIterator.java     | 13 +++++--------
 4 files changed, 19 insertions(+), 24 deletions(-)


(commons-beanutils) 04/04: ResultSetIterator.get(String) now throws IllegalArgumentException instead of RuntimeException to wrap cases of SQLException

Posted by gg...@apache.org.
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 54696927b3b736031ae57d16dd25e098b72facf1
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 28 16:17:00 2025 -0400

    ResultSetIterator.get(String) now throws IllegalArgumentException
    instead of RuntimeException to wrap cases of SQLException
    
    - ResultSetIterator.hasNext() now throws IllegalArgumentException
    instead of RuntimeException to wrap cases of SQLException
    - ResultSetIterator.set(String, Object) now throws
    IllegalArgumentException instead of RuntimeException to wrap cases of
    SQLException
    - ResultSetIterator.set(String, String, Object) now throws
    IllegalArgumentException instead of RuntimeException to wrap cases of
    SQLException.</action>
---
 src/changes/changes.xml                                     |  4 ++++
 .../org/apache/commons/beanutils/ResultSetIterator.java     | 13 +++++--------
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 77a10c3f..af012f3c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -32,6 +32,10 @@
       <!-- 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>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">MappedMethodReference.get() now throws IllegalStateException instead of RuntimeException to wrap cases of NoSuchMethodException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">ResultSetIterator.get(String) now throws IllegalArgumentException instead of RuntimeException to wrap cases of SQLException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">ResultSetIterator.hasNext() now throws IllegalArgumentException instead of RuntimeException to wrap cases of SQLException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">ResultSetIterator.set(String, Object) now throws IllegalArgumentException instead of RuntimeException to wrap cases of SQLException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">ResultSetIterator.set(String, String, Object) now throws IllegalArgumentException instead of RuntimeException to wrap cases of SQLException.</action>
       <!-- ADD -->
       <!-- UPDATE -->
     </release>
diff --git a/src/main/java/org/apache/commons/beanutils/ResultSetIterator.java b/src/main/java/org/apache/commons/beanutils/ResultSetIterator.java
index c076e9dc..cb20bad6 100644
--- a/src/main/java/org/apache/commons/beanutils/ResultSetIterator.java
+++ b/src/main/java/org/apache/commons/beanutils/ResultSetIterator.java
@@ -110,8 +110,7 @@ public class ResultSetIterator implements DynaBean, Iterator<DynaBean> {
         try {
             return dynaClass.getObjectFromResultSet(name);
         } catch (final SQLException e) {
-            throw new RuntimeException
-                ("get(" + name + "): SQLException: " + e);
+            throw new IllegalArgumentException("get(" + name + "): SQLException: " + e, e);
         }
     }
 
@@ -177,7 +176,7 @@ public class ResultSetIterator implements DynaBean, Iterator<DynaBean> {
             advance();
             return !eof;
         } catch (final SQLException e) {
-            throw new RuntimeException("hasNext():  SQLException:  " + e);
+            throw new IllegalArgumentException("hasNext():  SQLException:  " + e, e);
         }
     }
 
@@ -196,7 +195,7 @@ public class ResultSetIterator implements DynaBean, Iterator<DynaBean> {
             current = false;
             return this;
         } catch (final SQLException e) {
-            throw new RuntimeException("next():  SQLException:  " + e);
+            throw new IllegalArgumentException("next():  SQLException:  " + e, e);
         }
 
     }
@@ -267,8 +266,7 @@ public class ResultSetIterator implements DynaBean, Iterator<DynaBean> {
         try {
             dynaClass.getResultSet().updateObject(name, value);
         } catch (final SQLException e) {
-            throw new RuntimeException
-                ("set(" + name + "): SQLException: " + e);
+            throw new IllegalArgumentException("set(" + name + "): SQLException: " + e, e);
         }
     }
 
@@ -287,8 +285,7 @@ public class ResultSetIterator implements DynaBean, Iterator<DynaBean> {
      */
     @Override
     public void set(final String name, final String key, final Object value) {
-        throw new UnsupportedOperationException
-            ("FIXME - mapped properties not currently supported");
+        throw new UnsupportedOperationException("FIXME - mapped properties not currently supported");
     }
 
 }


(commons-beanutils) 03/04: MappedMethodReference.get() now throws IllegalStateException instead of RuntimeException to wrap cases of NoSuchMethodException

Posted by gg...@apache.org.
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 b1f5abce013b1dcdf08af94944746ace2a458701
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 28 15:35:52 2025 -0400

    MappedMethodReference.get() now throws IllegalStateException instead of
    RuntimeException to wrap cases of NoSuchMethodException
---
 src/changes/changes.xml                                                 | 1 +
 .../java/org/apache/commons/beanutils/MappedPropertyDescriptor.java     | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6b01d13d..77a10c3f 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -31,6 +31,7 @@
     <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>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">MappedMethodReference.get() now throws IllegalStateException instead of RuntimeException to wrap cases of NoSuchMethodException.</action>
       <!-- ADD -->
       <!-- UPDATE -->
     </release>
diff --git a/src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java b/src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java
index 5cece7d6..23a463fd 100644
--- a/src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java
+++ b/src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java
@@ -122,7 +122,7 @@ public class MappedPropertyDescriptor extends PropertyDescriptor {
                     // Un-comment following line for testing
                     // System.out.println("Recreated Method " + methodName + " for " + className);
                 } catch (final NoSuchMethodException e) {
-                    throw new RuntimeException("Method " + methodName + " for " + className + " could not be reconstructed - method not found", e);
+                    throw new IllegalStateException("Method " + methodName + " for " + className + " could not be reconstructed - method not found", e);
                 }
                 methodRef = new SoftReference<>(m);
             }


(commons-beanutils) 01/04: BeanComparator.compare(T, T) now throws IllegalArgumentException instead of RuntimeException to wrap all cases of ReflectiveOperationException

Posted by gg...@apache.org.
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 <ga...@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);
         }
     }
 


(commons-beanutils) 02/04: Use Objects.requireNonNull()

Posted by gg...@apache.org.
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 8bb5e61bba3c2e01810952e85a9643c17d96cec0
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Mon Apr 28 15:34:09 2025 -0400

    Use Objects.requireNonNull()
---
 .../apache/commons/beanutils/MappedPropertyDescriptor.java    | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java b/src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java
index 83034198..5cece7d6 100644
--- a/src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java
+++ b/src/main/java/org/apache/commons/beanutils/MappedPropertyDescriptor.java
@@ -24,6 +24,7 @@ import java.lang.ref.SoftReference;
 import java.lang.ref.WeakReference;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.util.Objects;
 
 /**
  * A MappedPropertyDescriptor describes one mapped property.
@@ -50,6 +51,7 @@ public class MappedPropertyDescriptor extends PropertyDescriptor {
      * See http://issues.apache.org/jira/browse/BEANUTILS-291
      */
     private static class MappedMethodReference {
+
         private String className;
         private String methodName;
         private Reference<Method> methodRef;
@@ -57,6 +59,7 @@ public class MappedPropertyDescriptor extends PropertyDescriptor {
         private Reference<Class<?>> writeParamTypeRef0;
         private Reference<Class<?>> writeParamTypeRef1;
         private String[] writeParamClassNames;
+
         MappedMethodReference(final Method m) {
             if (m != null) {
                 className = m.getDeclaringClass().getName();
@@ -91,10 +94,7 @@ public class MappedPropertyDescriptor extends PropertyDescriptor {
                         classRef = new WeakReference<>(clazz);
                     }
                 }
-                if (clazz == null) {
-                    throw new RuntimeException("Method " + methodName + " for " +
-                            className + " could not be reconstructed - class reference has gone");
-                }
+                Objects.requireNonNull(clazz, () -> "Method " + methodName + " for " + className + " could not be reconstructed - class reference has gone");
                 Class<?>[] paramTypes = null;
                 if (writeParamClassNames != null) {
                     paramTypes = new Class[2];
@@ -122,8 +122,7 @@ public class MappedPropertyDescriptor extends PropertyDescriptor {
                     // Un-comment following line for testing
                     // System.out.println("Recreated Method " + methodName + " for " + className);
                 } catch (final NoSuchMethodException e) {
-                    throw new RuntimeException("Method " + methodName + " for " +
-                            className + " could not be reconstructed - method not found");
+                    throw new RuntimeException("Method " + methodName + " for " + className + " could not be reconstructed - method not found", e);
                 }
                 methodRef = new SoftReference<>(m);
             }