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 2023/06/23 13:59:04 UTC

[commons-jxpath] 02/02: ValueUtils.setValue() now throws IllegalArgumentException instead of RuntimeException.

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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jxpath.git

commit c05ba079c977d6ee70d9e2e81604f7c4cbe8ec07
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jun 23 09:58:58 2023 -0400

    ValueUtils.setValue() now throws IllegalArgumentException instead of
    RuntimeException.
---
 src/changes/changes.xml                                 |  5 ++++-
 .../java/org/apache/commons/jxpath/util/ValueUtils.java | 17 ++++-------------
 2 files changed, 8 insertions(+), 14 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index d582b7c..6f07cb8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -88,7 +88,10 @@ The <action> type attribute can be add,update,fix,remove.
       </action>
       <action dev="ggregory" type="fix" due-to="Gary Gregory">
         JDOMNodePointer.compareChildNodePointers() now throws IllegalStateException instead of RuntimeException.
-      </action>      
+      </action>
+      <action dev="ggregory" type="fix" due-to="Gary Gregory">
+        ValueUtils.setValue() now throws IllegalArgumentException instead of RuntimeException.
+      </action>
       <!-- ADD -->
       <action issue="JXPATH-123" dev="mbenson" type="add">
         XPath function "ends-with" is not implemented (although "starts-with" is).
diff --git a/src/main/java/org/apache/commons/jxpath/util/ValueUtils.java b/src/main/java/org/apache/commons/jxpath/util/ValueUtils.java
index 843715a..ecee382 100644
--- a/src/main/java/org/apache/commons/jxpath/util/ValueUtils.java
+++ b/src/main/java/org/apache/commons/jxpath/util/ValueUtils.java
@@ -478,23 +478,15 @@ public class ValueUtils {
             final PropertyDescriptor propertyDescriptor, final int index, final Object value) {
         if (propertyDescriptor instanceof IndexedPropertyDescriptor) {
             try {
-                final IndexedPropertyDescriptor ipd =
-                    (IndexedPropertyDescriptor) propertyDescriptor;
+                final IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) propertyDescriptor;
                 final Method method = ipd.getIndexedWriteMethod();
                 if (method != null) {
-                    method.invoke(
-                        bean,
-                            Integer.valueOf(index),
-                            convert(value, ipd.getIndexedPropertyType()));
+                    method.invoke(bean, Integer.valueOf(index), convert(value, ipd.getIndexedPropertyType()));
                     return;
                 }
             }
             catch (final Exception ex) {
-                throw new RuntimeException(
-                    "Cannot access property: "
-                        + propertyDescriptor.getName()
-                        + ", "
-                        + ex.getMessage());
+                throw new IllegalArgumentException("Cannot access property: " + propertyDescriptor.getName() + ", " + ex.getMessage());
             }
         }
         // We will fall through if there is no indexed read
@@ -506,8 +498,7 @@ public class ValueUtils {
             setValue(bean, propertyDescriptor, value);
         }
         else {
-            throw new RuntimeException(
-                "Not a collection: " + propertyDescriptor.getName());
+            throw new IllegalArgumentException("Not a collection: " + propertyDescriptor.getName());
         }
     }