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-jexl.git


The following commit(s) were added to refs/heads/master by this push:
     new 71b1353d Add and use CoercionException.CoercionException(String, 
Throwable)
71b1353d is described below

commit 71b1353d8704cb95684418b2a56ba5882cd2db4f
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Sat Feb 15 14:22:17 2025 -0500

    Add and use CoercionException.CoercionException(String, Throwable)
    
    Welcome to Java 6+ ;)
---
 src/changes/changes.xml                            |  3 +++
 .../org/apache/commons/jexl3/JexlArithmetic.java   | 29 ++++++++++++++--------
 2 files changed, 21 insertions(+), 11 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 6c615c3d..9a41f4ff 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -67,6 +67,9 @@
             <action dev="henrib" type="add" issue="JEXL-426" due-to="Xu 
Pengcheng">
                 Enable pass-by-reference for Captured Variables.
             </action>
+            <action dev="ggregory" type="add" due-to="Gary Gregory">
+                Add and use CoercionException.CoercionException(String, 
Throwable).
+            </action>
           <!-- UPDATE -->
           <action type="update" dev="ggregory" due-to="Gary Gregory">Bump 
org.apache.commons:commons-parent from 71 to 79 #279, #282, #287, #291, #295, 
#301.</action>
           <action type="update" dev="ggregory">Bump 
commons-logging:commons-logging from 1.3.2 to 1.3.5 #267, #280, #325.</action>
diff --git a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java 
b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
index 5240c669..93c9b96f 100644
--- a/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
+++ b/src/main/java/org/apache/commons/jexl3/JexlArithmetic.java
@@ -94,12 +94,25 @@ public class JexlArithmetic {
         private static final long serialVersionUID = 202402081150L;
 
         /**
-         * Simple ctor.
-         * @param msg the exception message
+         * Constructs a new instance.
+         *
+         * @param msg the detail message.
          */
         public CoercionException(final String msg) {
             super(msg);
         }
+
+        /**
+         * Constructs a new instance.
+         *
+         * @param msg the detail message.
+         * @param cause The cause of this Throwable.
+         * @since 3.5.0
+         */
+        public CoercionException(final String msg, final Throwable cause) {
+            super(msg);
+            initCause(cause);
+        }
     }
 
     /**
@@ -1649,9 +1662,7 @@ public class JexlArithmetic {
         try {
             return arg.isEmpty()? BigDecimal.ZERO : new BigDecimal(arg, 
getMathContext());
         } catch (final NumberFormatException e) {
-            final ArithmeticException arithmeticException = new 
CoercionException("BigDecimal coercion: ("+ arg +")");
-            arithmeticException.initCause(e);
-            throw arithmeticException;
+            throw new CoercionException("BigDecimal coercion: ("+ arg +")", e);
         }
     }
 
@@ -1666,9 +1677,7 @@ public class JexlArithmetic {
         try {
             return arg.isEmpty()? BigInteger.ZERO : new BigInteger(arg);
         } catch (final NumberFormatException e) {
-            final ArithmeticException arithmeticException = new 
CoercionException("BigDecimal coercion: ("+ arg +")");
-            arithmeticException.initCause(e);
-            throw arithmeticException;
+            throw new CoercionException("BigDecimal coercion: ("+ arg +")", e);
         }
     }
 
@@ -1683,9 +1692,7 @@ public class JexlArithmetic {
         try {
             return arg.isEmpty()? Double.NaN : Double.parseDouble(arg);
         } catch (final NumberFormatException e) {
-            final ArithmeticException arithmeticException = new 
CoercionException("Double coercion: ("+ arg +")");
-            arithmeticException.initCause(e);
-            throw arithmeticException;
+            throw new CoercionException("Double coercion: ("+ arg +")", e);
         }
     }
 

Reply via email to