Skip to content

Commit c3cee71

Browse files
authored
Merge pull request #1763 from marklogic/feature/polaris-null-references
MLE-21383 Addressing Polaris null references
2 parents 53d4918 + dc050bf commit c3cee71

File tree

11 files changed

+63
-33
lines changed

11 files changed

+63
-33
lines changed

examples/src/main/java/com/marklogic/client/example/extension/SearchCollectorExample.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.io.File;
1818
import java.io.IOException;
1919
import java.io.InputStream;
20+
import java.util.Objects;
2021

2122
/**
2223
* SearchCollectorExample illustrates reading a page of documents
@@ -174,6 +175,7 @@ public static void useResource(ExampleProperties props) {
174175
CollectorResults results = collector.collect(
175176
"neighborhood industry:\"Real Estate\"", 1, OPTIONS_NAME
176177
);
178+
Objects.requireNonNull(results);
177179

178180
System.out.println();
179181
System.out.println("search results:");

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/NoResponseListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public NoResponseListener(DataMovementManager moveMgr) {
3333
protected boolean isHostUnavailableException(Throwable throwable, Set<Throwable> path) {
3434
// Check if the exception is an IOException and check if the
3535
// message indicates an end of stream on a Connection.
36-
if ( IOException.class.isInstance(throwable) && throwable.getMessage().contains("unexpected end of stream on") ) {
36+
if ( IOException.class.isInstance(throwable) && (throwable.getMessage() != null && throwable.getMessage().contains("unexpected end of stream on"))) {
3737
return true;
3838
}
3939
// we need to check our recursion path to avoid infinite recursion if a

marklogic-client-api/src/main/java/com/marklogic/client/dataservices/impl/IOCallerImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import com.marklogic.client.io.marker.BufferableContentHandle;
1515
import com.marklogic.client.io.marker.JSONWriteHandle;
1616

17+
import java.util.Objects;
18+
1719
abstract class IOCallerImpl<I,O> extends BaseCallerImpl {
1820
private final JsonNode apiDeclaration;
1921
private final String endpointPath;
@@ -36,6 +38,7 @@ abstract class IOCallerImpl<I,O> extends BaseCallerImpl {
3638
}
3739

3840
this.apiDeclaration = NodeConverter.handleToJsonNode(apiDeclaration);
41+
Objects.requireNonNull(this.apiDeclaration);
3942
if (!this.apiDeclaration.isObject()) {
4043
throw new IllegalArgumentException(
4144
"endpoint declaration must be object: " + this.apiDeclaration

marklogic-client-api/src/main/java/com/marklogic/client/impl/JacksonBaseHandle.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.io.OutputStream;
1111
import java.io.UnsupportedEncodingException;
1212
import java.nio.charset.StandardCharsets;
13+
import java.util.Objects;
1314

1415
import com.fasterxml.jackson.core.JsonParser;
1516
import com.fasterxml.jackson.core.JsonGenerator;
@@ -69,8 +70,10 @@ public byte[] contentToBytes(T content) {
6970
if (!hasContent())
7071
return null;
7172

72-
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
73-
sendContent(content).write(buffer);
73+
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
74+
OutputStreamSender sender = sendContent(content);
75+
Objects.requireNonNull(sender);
76+
sender.write(buffer);
7477

7578
return buffer.toByteArray();
7679
} catch (IOException e) {

marklogic-client-api/src/main/java/com/marklogic/client/impl/OkHttpServices.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
package com.marklogic.client.impl;
55

6+
import com.fasterxml.jackson.core.JsonParser;
67
import com.fasterxml.jackson.databind.JsonNode;
78
import com.fasterxml.jackson.databind.ObjectMapper;
89
import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -399,6 +400,7 @@ public Response apply(Request.Builder funcBuilder) {
399400
}
400401
};
401402
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doDeleteFunction, null);
403+
Objects.requireNonNull(response);
402404
int status = response.code();
403405

404406
if (status == STATUS_NOT_FOUND) {
@@ -539,7 +541,7 @@ private Response sendRequestWithRetry(
539541
response = doFunction.apply(requestBldr);
540542
if (response == null) {
541543
throw new MarkLogicInternalException(
542-
"null response for: " + requestBldr.build().url().toString()
544+
"null response for: " + requestBldr.build().url()
543545
);
544546
}
545547
status = response.code();
@@ -1019,6 +1021,7 @@ public ConnectionResult checkConnection() {
10191021
private Response headImpl(RequestLogger reqlog, String uri,
10201022
Transaction transaction, Request.Builder requestBldr) {
10211023
Response response = headImplExec(reqlog, uri, transaction, requestBldr);
1024+
Objects.requireNonNull(response);
10221025
int status = response.code();
10231026
if (status != STATUS_OK) {
10241027
if (status == STATUS_NOT_FOUND) {
@@ -1567,6 +1570,7 @@ public Response apply(Request.Builder funcBuilder) {
15671570
}
15681571
};
15691572
Response response = sendRequestWithRetry(requestBldr, false, doPostFunction, null);
1573+
Objects.requireNonNull(response);
15701574
int status = response.code();
15711575

15721576
if (status == STATUS_FORBIDDEN) {
@@ -1911,10 +1915,9 @@ public <T extends SearchReadHandle> T search(RequestLogger reqlog, T searchHandl
19111915
throw new UnsupportedOperationException("Only XML and JSON search results are possible.");
19121916
}
19131917

1914-
String mimetype = searchFormat.getDefaultMimetype();
1918+
String mimetype = searchFormat != null ? searchFormat.getDefaultMimetype() : null;
19151919

19161920
OkHttpSearchRequest request = generateSearchRequest(reqlog, queryDef, mimetype, transaction, null, params, forestName);
1917-
19181921
Response response = request.getResponse();
19191922
if (response == null) return null;
19201923

@@ -2208,6 +2211,7 @@ public Response apply(Request.Builder funcBuilder) {
22082211
}
22092212
};
22102213
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doDeleteFunction, null);
2214+
Objects.requireNonNull(response);
22112215
int status = response.code();
22122216
if (status == STATUS_FORBIDDEN) {
22132217
throw new ForbiddenUserException("User is not allowed to delete",
@@ -2376,6 +2380,7 @@ public Response apply(Request.Builder funcBuilder) {
23762380
};
23772381

23782382
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doFunction, null);
2383+
Objects.requireNonNull(response);
23792384
int status = response.code();
23802385

23812386
if (status == STATUS_FORBIDDEN) {
@@ -2424,6 +2429,7 @@ public Response apply(Request.Builder funcBuilder) {
24242429
}
24252430
};
24262431
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doGetFunction, null);
2432+
Objects.requireNonNull(response);
24272433
int status = response.code();
24282434

24292435
if (status == STATUS_FORBIDDEN) {
@@ -2466,6 +2472,7 @@ public Response apply(Request.Builder funcBuilder) {
24662472
}
24672473
};
24682474
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doGetFunction, null);
2475+
Objects.requireNonNull(response);
24692476
int status = response.code();
24702477

24712478
if (status == STATUS_FORBIDDEN) {
@@ -2510,6 +2517,7 @@ public Response apply(Request.Builder funcBuilder) {
25102517
}
25112518
};
25122519
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doGetFunction, null);
2520+
Objects.requireNonNull(response);
25132521
int status = response.code();
25142522

25152523
if (status != STATUS_OK) {
@@ -2990,6 +2998,7 @@ public Response apply(Request.Builder funcBuilder) {
29902998
}
29912999
};
29923000
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doGetFunction, null);
3001+
Objects.requireNonNull(response);
29933002
int status = response.code();
29943003
checkStatus(response, status, "read", "resource", path,
29953004
ResponseStatus.OK_OR_NO_CONTENT);
@@ -3030,10 +3039,9 @@ public Response apply(Request.Builder funcBuilder) {
30303039
}
30313040
};
30323041
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doGetFunction, null);
3042+
Objects.requireNonNull(response);
30333043
int status = response.code();
3034-
checkStatus(response, status, "read", "resource", path,
3035-
ResponseStatus.OK_OR_NO_CONTENT);
3036-
3044+
checkStatus(response, status, "read", "resource", path, ResponseStatus.OK_OR_NO_CONTENT);
30373045
return makeResults(constructor, reqlog, "read", "resource", response);
30383046
}
30393047

@@ -3076,6 +3084,7 @@ public Response apply(Request.Builder funcBuilder) {
30763084
}
30773085
};
30783086
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doPutFunction, resendableConsumer);
3087+
Objects.requireNonNull(response);
30793088
int status = response.code();
30803089

30813090
checkStatus(response, status, "write", "resource", path,
@@ -3162,8 +3171,9 @@ public <R extends AbstractReadHandle, W extends AbstractWriteHandle> R putResour
31623171
ResponseStatus.OK_OR_CREATED_OR_NO_CONTENT);
31633172

31643173
if (as != null) {
3165-
outputBase.receiveContent(makeResult(reqlog, "write", "resource",
3166-
response, as));
3174+
Object content = makeResult(reqlog, "write", "resource", response, as);
3175+
Objects.requireNonNull(content);
3176+
outputBase.receiveContent(content);
31673177
} else {
31683178
closeResponse(response);
31693179
}
@@ -3640,13 +3650,14 @@ public EvalResultIterator postEvalInvoke(
36403650
if (valueObject == null) {
36413651
value = "null";
36423652
type = "null-node()";
3643-
} else if (valueObject instanceof JacksonHandle ||
3644-
valueObject instanceof JacksonParserHandle) {
3653+
} else if (valueObject instanceof JacksonHandle || valueObject instanceof JacksonParserHandle) {
36453654
JsonNode jsonNode = null;
36463655
if (valueObject instanceof JacksonHandle) {
36473656
jsonNode = ((JacksonHandle) valueObject).get();
36483657
} else if (valueObject instanceof JacksonParserHandle) {
3649-
jsonNode = ((JacksonParserHandle) valueObject).get().readValueAs(JsonNode.class);
3658+
JsonParser jsonParser = ((JacksonParserHandle) valueObject).get();
3659+
Objects.requireNonNull(jsonParser);
3660+
jsonNode = jsonParser.readValueAs(JsonNode.class);
36503661
}
36513662
value = jsonNode.toString();
36523663
type = getJsonType(jsonNode);
@@ -3690,7 +3701,7 @@ public EvalResultIterator postEvalInvoke(
36903701

36913702
// set the variable value
36923703
sb.append("&evv" + i + "=");
3693-
sb.append(URLEncoder.encode(value, "UTF-8"));
3704+
sb.append(value != null ? URLEncoder.encode(value, "UTF-8") : value);
36943705
// set the variable type
36953706
sb.append("&evt" + i + "=" + type);
36963707
i++;
@@ -3973,6 +3984,7 @@ public Response apply(Request.Builder funcBuilder) {
39733984
}
39743985
};
39753986
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doDeleteFunction, null);
3987+
Objects.requireNonNull(response);
39763988
int status = response.code();
39773989
checkStatus(response, status, "delete", "resource", path,
39783990
ResponseStatus.OK_OR_NO_CONTENT);

marklogic-client-api/src/main/java/com/marklogic/client/impl/QueryManagerImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,10 @@ public <T extends QueryOptionsListReadHandle> T optionsList(T optionsHandle, Tra
311311

312312
String mimetype = optionsFormat.getDefaultMimetype();
313313

314-
String tid = transaction == null ? null : transaction.getTransactionId();
315-
optionsBase.receiveContent(services.optionsList(optionsBase.receiveAs(), mimetype, transaction));
314+
Object content = services.optionsList(optionsBase.receiveAs(), mimetype, transaction);
315+
if (content != null) {
316+
optionsBase.receiveContent(content);
317+
}
316318
return optionsHandle;
317319
}
318320

marklogic-client-api/src/main/java/com/marklogic/client/impl/QueryOptionsManagerImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,10 @@ public <T extends QueryOptionsListReadHandle> T optionsList(T optionsHandle)
182182
}
183183

184184
String mimetype = optionsFormat.getDefaultMimetype();
185-
186-
optionsBase.receiveContent(services.optionsList(optionsBase.receiveAs(), mimetype, null));
185+
Object content = services.optionsList(optionsBase.receiveAs(), mimetype, null);
186+
if (content != null) {
187+
optionsBase.receiveContent(content);
188+
}
187189
return optionsHandle;
188190
}
189191
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/ResourceExtensionsImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ public <T extends StructureReadHandle> T listServices(T listHandle, boolean refr
8888
extraParams.put("refresh", "false");
8989
}
9090

91-
listBase.receiveContent(
92-
services.getValues(requestLogger, "config/resources", extraParams,
93-
listFormat.getDefaultMimetype(), listBase.receiveAs())
94-
);
91+
Object content = services.getValues(requestLogger, "config/resources", extraParams, listFormat.getDefaultMimetype(), listBase.receiveAs());
92+
if (content != null) {
93+
listBase.receiveContent(content);
94+
}
9595

9696
return listHandle;
9797
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/TransformExtensionsImpl.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,10 @@ public <T extends StructureReadHandle> T listTransforms(T listHandle, boolean re
9898
extraParams.put("refresh", "false");
9999
}
100100

101-
listBase.receiveContent(
102-
services.getValues(requestLogger, "config/transforms", extraParams,
103-
listFormat.getDefaultMimetype(), listBase.receiveAs())
104-
);
105-
101+
Object content = services.getValues(requestLogger, "config/transforms", extraParams, listFormat.getDefaultMimetype(), listBase.receiveAs());
102+
if (content != null) {
103+
listBase.receiveContent(content);
104+
}
106105
return listHandle;
107106
}
108107

marklogic-client-api/src/main/java/com/marklogic/client/io/JSONErrorParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import java.io.InputStream;
1111
import java.util.Map;
12+
import java.util.Objects;
1213

1314
public class JSONErrorParser implements FailedRequestParser {
1415

@@ -23,7 +24,7 @@ public FailedRequest parseFailedRequest(int httpStatus, InputStream content) {
2324
} catch (Exception ex) {
2425
return new FailedRequest(httpStatus, "Request failed; could not parse JSON in response body.");
2526
}
26-
27+
Objects.requireNonNull(errorData);
2728
if (!errorData.containsKey("errorResponse")) {
2829
return new FailedRequest(httpStatus, "Unexpected JSON in response body; did not find 'errorResponse' key; response: " + errorData);
2930
}

0 commit comments

Comments
 (0)