Skip to content

Commit 02013b4

Browse files
Merge pull request #1972 from marklogic/MLE-32022
MLE-32022 Avoid null pointer exception when FailedRequest is null
2 parents 6b79717 + b539def commit 02013b4

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎marklogic-client-api/src/main/java/com/marklogic/client/MarkLogicServerException.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/*
2-
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
2+
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33
*/
44
package com.marklogic.client;
55

66
import com.marklogic.client.impl.FailedRequest;
7+
import com.marklogic.client.impl.RESTServices;
78

89
/**
910
* Abstract class that implements functionality for errors returned from a MarkLogic REST API instance.
@@ -51,7 +52,7 @@ else if (failedRequest != null) {
5152
* @return the status code
5253
*/
5354
public int getServerStatusCode() {
54-
return (failedRequest == null) ? null : failedRequest.getStatusCode();
55+
return (failedRequest == null) ? RESTServices.STATUS_UNKNOWN : failedRequest.getStatusCode();
5556
}
5657
/**
5758
* Gets the HTTP status message (if any) associated with the error on the server.

‎marklogic-client-api/src/main/java/com/marklogic/client/impl/RESTServices.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
2+
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33
*/
44
package com.marklogic.client.impl;
55

@@ -68,6 +68,7 @@ public interface RESTServices {
6868
String MIMETYPE_APPLICATION_XML = "application/xml";
6969
String MIMETYPE_MULTIPART_MIXED = "multipart/mixed";
7070

71+
int STATUS_UNKNOWN = -1;
7172
int STATUS_OK = 200;
7273
int STATUS_CREATED = 201;
7374
int STATUS_NO_CONTENT = 204;

‎marklogic-client-api/src/test/java/com/marklogic/client/test/FailedRequestTest.java‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/*
2-
* Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
2+
* Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
33
*/
44
package com.marklogic.client.test;
55

66
import com.marklogic.client.*;
77
import com.marklogic.client.admin.QueryOptionsManager;
88
import com.marklogic.client.document.XMLDocumentManager;
9+
import com.marklogic.client.impl.FailedRequest;
910
import com.marklogic.client.io.Format;
1011
import com.marklogic.client.io.StringHandle;
1112
import org.junit.jupiter.api.Test;
@@ -100,4 +101,15 @@ public void testFailedRequestParsing() {
100101
fail("Call failed with unexpected exception: "+e.getMessage());
101102
}
102103
}
104+
105+
@Test
106+
public void testNullFailedRequestInFailedRequestException() {
107+
FailedRequestException e = new FailedRequestException("test", (FailedRequest) null);
108+
assertEquals("test", e.getMessage());
109+
assertEquals(-1, e.getServerStatusCode());
110+
assertNull(e.getServerStatus());
111+
assertNull(e.getServerMessageCode());
112+
assertNull(e.getServerMessage());
113+
assertNull(e.getServerStackTrace());
114+
}
103115
}

0 commit comments

Comments
 (0)