Skip to content

Commit c93e58e

Browse files
[refactor] Fix NullPointerException test exceptions.
1 parent 8b8c3fa commit c93e58e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

exist-core/src/main/java/org/exist/xquery/XPathException.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public XPathException(final XQueryAST ast, final ErrorCode errorCode, final Stri
172172
@Deprecated
173173
public XPathException(final Throwable cause) {
174174
super(cause);
175-
if(cause instanceof XPathErrorProvider) {
175+
if (cause != null && cause instanceof XPathErrorProvider) {
176176
this.errorCode = ((XPathErrorProvider)cause).getErrorCode();
177177
}
178178
}
@@ -190,7 +190,7 @@ public XPathException(final String message, final Throwable cause) {
190190
public XPathException(final Expression expr, final String message, final Throwable cause) {
191191
super(cause);
192192
this.message = message;
193-
if(cause instanceof XPathErrorProvider) {
193+
if (cause != null && cause instanceof XPathErrorProvider) {
194194
this.errorCode = ((XPathErrorProvider)cause).getErrorCode();
195195
}
196196

@@ -208,7 +208,7 @@ public XPathException(final Expression expr, final String message, final Throwab
208208
*/
209209
@Deprecated
210210
public XPathException(final Expression expr, final Throwable cause) {
211-
this(expr, cause instanceof XPathErrorProvider ? ((XPathErrorProvider)cause).getErrorCode() : ErrorCodes.ERROR, cause.getMessage(), null, cause);
211+
this(expr, cause != null && cause instanceof XPathErrorProvider ? ((XPathErrorProvider)cause).getErrorCode() : ErrorCodes.ERROR, cause.getMessage(), null, cause);
212212
}
213213

214214
/**
@@ -222,7 +222,9 @@ public XPathException(final ErrorCode errorCode, final String errorDesc) {
222222
this.errorCode = errorCode;
223223

224224
if(errorDesc == null){
225-
this.message = errorCode.toString();
225+
if (errorCode != null) {
226+
this.message = errorCode.toString();
227+
}
226228
} else {
227229
this.message = errorDesc;
228230
}
@@ -238,7 +240,9 @@ public XPathException(final ErrorCode errorCode, final String errorDesc, final T
238240
this.errorCode = errorCode;
239241

240242
if(errorDesc == null){
241-
this.message = errorCode.toString();
243+
if (errorCode != null) {
244+
this.message = errorCode.toString();
245+
}
242246
} else {
243247
this.message = errorDesc;
244248
}
@@ -254,7 +258,9 @@ public XPathException(final Expression expr, final ErrorCode errorCode, final St
254258
this.errorCode = errorCode;
255259

256260
if(errorDesc == null){
257-
this.message = errorCode.toString();
261+
if (errorCode != null) {
262+
this.message = errorCode.toString();
263+
}
258264
} else {
259265
this.message = errorDesc;
260266
}
@@ -279,7 +285,7 @@ protected XPathException(final int line, final int column, final String message,
279285
this.message = message;
280286
this.line = line;
281287
this.column = column;
282-
if(cause instanceof XPathErrorProvider) {
288+
if (cause != null && cause instanceof XPathErrorProvider) {
283289
this.errorCode = ((XPathErrorProvider)cause).getErrorCode();
284290
}
285291
}

0 commit comments

Comments
 (0)