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 61e8dd0241423217553acc0a9fb4ed96a85107c7
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Mon Mar 17 15:16:27 2025 -0400

    JXPathException now reuses its superclass' Throwable cause
---
 src/changes/changes.xml                            |  1 +
 .../org/apache/commons/jxpath/JXPathException.java | 50 +++-------------------
 2 files changed, 8 insertions(+), 43 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 84de454..2c9b0f2 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -116,6 +116,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="fix" due-to="Gary Gregory">Deprecate 
ValueUtils.ValueUtils().</action>
       <action dev="ggregory" type="fix" due-to="Gary 
Gregory">PageScopeContext.getAttributeNames() is now typed with 
generics.</action>
       <action dev="ggregory" type="fix" due-to="Gary 
Gregory">Functions.getUsedNamespaces() is now typed with generics.</action>
+      <action dev="ggregory" type="fix" due-to="Gary Gregory">JXPathException 
now reuses its superclass' Throwable cause.</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/JXPathException.java 
b/src/main/java/org/apache/commons/jxpath/JXPathException.java
index 956a4b8..999744a 100644
--- a/src/main/java/org/apache/commons/jxpath/JXPathException.java
+++ b/src/main/java/org/apache/commons/jxpath/JXPathException.java
@@ -23,14 +23,11 @@ package org.apache.commons.jxpath;
 public class JXPathException extends RuntimeException {
 
     private static final long serialVersionUID = 4306409701468017766L;
-    /** @serial */
-    private final Throwable exception;
 
     /**
      * Create a new {@code JXPathException} with no detail mesage.
      */
     public JXPathException() {
-        this.exception = null;
     }
 
     /**
@@ -40,38 +37,25 @@ public class JXPathException extends RuntimeException {
      */
     public JXPathException(final String msg) {
         super(msg);
-        this.exception = null;
     }
 
     /**
      * Create a new {@code JXPathException} with the given {@code Exception} 
base cause and detail message.
      *
      * @param msg The detail message.
-     * @param e   The exception to be encapsulated in a JXPathException
+     * @param cause   The exception to be encapsulated in a JXPathException
      */
-    public JXPathException(final String msg, final Throwable e) {
-        super(msg);
-        this.exception = e;
+    public JXPathException(final String msg, final Throwable cause) {
+        super(msg, cause);
     }
 
     /**
      * Create a new {@code JXPathException} with a given {@code Throwable} 
base cause of the error.
      *
-     * @param e The exception to be encapsulated in a JXPathException.
-     */
-    public JXPathException(final Throwable e) {
-        super(e.toString());
-        this.exception = e;
-    }
-
-    /**
-     * Same as {@link #getException() getException()}
-     * 
-     * @return The encapsulated exception, or null if there is none.
+     * @param cause The exception to be encapsulated in a JXPathException.
      */
-    @Override
-    public Throwable getCause() {
-        return exception;
+    public JXPathException(final Throwable cause) {
+        super(cause.toString());
     }
 
     /**
@@ -80,27 +64,7 @@ public class JXPathException extends RuntimeException {
      * @return The encapsulated exception, or null if there is none.
      */
     public Throwable getException() {
-        return exception;
+        return super.getCause();
     }
 
-    /**
-     * Gets the message (if any) for this error . If there is no message for 
the exception and there is an encapsulated exception then the message of that
-     * exception will be returned.
-     *
-     * @return The error message.
-     */
-    @Override
-    public String getMessage() {
-        final String message = super.getMessage();
-        if (exception == null) {
-            return message;
-        }
-        final StringBuilder buf = new StringBuilder();
-        if (message != null) {
-            buf.append(message).append("; ");
-        }
-        final String eMsg = exception.getMessage();
-        buf.append(eMsg == null ? exception.getClass().getName() : eMsg);
-        return buf.toString();
-    }
 }

Reply via email to