Skip to content

Commit 61e8dd0

Browse files
committed
JXPathException now reuses its superclass' Throwable cause
1 parent 85fcf8c commit 61e8dd0

File tree

2 files changed

+8
-43
lines changed

2 files changed

+8
-43
lines changed

src/changes/changes.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ The <action> type attribute can be add,update,fix,remove.
116116
<action dev="ggregory" type="fix" due-to="Gary Gregory">Deprecate ValueUtils.ValueUtils().</action>
117117
<action dev="ggregory" type="fix" due-to="Gary Gregory">PageScopeContext.getAttributeNames() is now typed with generics.</action>
118118
<action dev="ggregory" type="fix" due-to="Gary Gregory">Functions.getUsedNamespaces() is now typed with generics.</action>
119+
<action dev="ggregory" type="fix" due-to="Gary Gregory">JXPathException now reuses its superclass' Throwable cause.</action>
119120
<!-- ADD -->
120121
<action issue="JXPATH-123" dev="mbenson" type="add">
121122
XPath function "ends-with" is not implemented (although "starts-with" is).

src/main/java/org/apache/commons/jxpath/JXPathException.java

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,11 @@
2323
public class JXPathException extends RuntimeException {
2424

2525
private static final long serialVersionUID = 4306409701468017766L;
26-
/** @serial */
27-
private final Throwable exception;
2826

2927
/**
3028
* Create a new {@code JXPathException} with no detail mesage.
3129
*/
3230
public JXPathException() {
33-
this.exception = null;
3431
}
3532

3633
/**
@@ -40,38 +37,25 @@ public JXPathException() {
4037
*/
4138
public JXPathException(final String msg) {
4239
super(msg);
43-
this.exception = null;
4440
}
4541

4642
/**
4743
* Create a new {@code JXPathException} with the given {@code Exception} base cause and detail message.
4844
*
4945
* @param msg The detail message.
50-
* @param e The exception to be encapsulated in a JXPathException
46+
* @param cause The exception to be encapsulated in a JXPathException
5147
*/
52-
public JXPathException(final String msg, final Throwable e) {
53-
super(msg);
54-
this.exception = e;
48+
public JXPathException(final String msg, final Throwable cause) {
49+
super(msg, cause);
5550
}
5651

5752
/**
5853
* Create a new {@code JXPathException} with a given {@code Throwable} base cause of the error.
5954
*
60-
* @param e The exception to be encapsulated in a JXPathException.
61-
*/
62-
public JXPathException(final Throwable e) {
63-
super(e.toString());
64-
this.exception = e;
65-
}
66-
67-
/**
68-
* Same as {@link #getException() getException()}
69-
*
70-
* @return The encapsulated exception, or null if there is none.
55+
* @param cause The exception to be encapsulated in a JXPathException.
7156
*/
72-
@Override
73-
public Throwable getCause() {
74-
return exception;
57+
public JXPathException(final Throwable cause) {
58+
super(cause.toString());
7559
}
7660

7761
/**
@@ -80,27 +64,7 @@ public Throwable getCause() {
8064
* @return The encapsulated exception, or null if there is none.
8165
*/
8266
public Throwable getException() {
83-
return exception;
67+
return super.getCause();
8468
}
8569

86-
/**
87-
* 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
88-
* exception will be returned.
89-
*
90-
* @return The error message.
91-
*/
92-
@Override
93-
public String getMessage() {
94-
final String message = super.getMessage();
95-
if (exception == null) {
96-
return message;
97-
}
98-
final StringBuilder buf = new StringBuilder();
99-
if (message != null) {
100-
buf.append(message).append("; ");
101-
}
102-
final String eMsg = exception.getMessage();
103-
buf.append(eMsg == null ? exception.getClass().getName() : eMsg);
104-
return buf.toString();
105-
}
10670
}

0 commit comments

Comments
 (0)