Skip to content

Commit 1d66359

Browse files
committed
MLE-26427 Fixing Polaris issues
Most of these already existed in OkHttpServices, but Polaris decided to report them recently
1 parent 95b274c commit 1d66359

File tree

3 files changed

+38
-13
lines changed

3 files changed

+38
-13
lines changed

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/ContentExclusionUtil.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ private static void removeNodeAtPointer(String uri, JsonNode rootNode, String js
8383
JsonNode parentNode = rootNode.at(parentPointer);
8484

8585
if (parentNode.isObject()) {
86-
String fieldName = pointer.last().getMatchingProperty();
87-
((ObjectNode) parentNode).remove(fieldName);
86+
JsonPointer lastSegment = pointer.last();
87+
if (lastSegment != null) {
88+
String fieldName = lastSegment.getMatchingProperty();
89+
((ObjectNode) parentNode).remove(fieldName);
90+
}
8891
} else if (parentNode.isArray()) {
8992
logger.warn("Array element exclusion not supported for JSONPointer '{}'. " +
9093
"Consider excluding the entire array property instead.", jsonPointer);

marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/IncrementalWriteFilter.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,15 @@ protected final DocumentWriteSet filterDocuments(Context context, Function<Strin
152152
continue;
153153
}
154154

155-
final String contentHash = computeHash(serializeContent(doc));
155+
final String serializedContent = serializeContent(doc);
156+
if (serializedContent == null) {
157+
// Not sure if the doc can have null content - possibly for a naked properties document? - but if it
158+
// does, just include it in the write set.
159+
newWriteSet.add(doc);
160+
continue;
161+
}
162+
163+
final String contentHash = computeHash(serializedContent);
156164
final String existingHash = hashRetriever.apply(doc.getUri());
157165
if (logger.isTraceEnabled()) {
158166
logger.trace("URI: {}, existing Hash: {}, new Hash: {}", doc.getUri(), existingHash, contentHash);
@@ -171,7 +179,7 @@ protected final DocumentWriteSet filterDocuments(Context context, Function<Strin
171179
}
172180
}
173181

174-
if (!skippedDocuments.isEmpty()) {
182+
if (!skippedDocuments.isEmpty() && skippedDocumentsConsumer != null) {
175183
skippedDocumentsConsumer.accept(skippedDocuments.toArray(new DocumentWriteOperation[0]));
176184
}
177185

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

Lines changed: 23 additions & 9 deletions
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

@@ -618,6 +618,7 @@ public Response apply(Request.Builder funcBuilder) {
618618
}
619619
};
620620
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doGetFunction, null);
621+
Objects.requireNonNull(response);
621622

622623
int status = response.code();
623624
if (status == STATUS_NOT_FOUND) {
@@ -659,7 +660,7 @@ public Response apply(Request.Builder funcBuilder) {
659660

660661
Class as = handleBase.receiveAs();
661662
ResponseBody body = response.body();
662-
Object entity = body.contentLength() != 0 ? getEntity(body, as) : null;
663+
Object entity = (body.contentLength() != 0) ? getEntity(body, as) : null;
663664

664665
if (entity == null || (!InputStream.class.isAssignableFrom(as) && !Reader.class.isAssignableFrom(as))) {
665666
closeResponse(response);
@@ -895,6 +896,7 @@ public Response apply(Request.Builder funcBuilder) {
895896
}
896897
};
897898
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doGetFunction, null);
899+
Objects.requireNonNull(response);
898900
int status = response.code();
899901
if (status == STATUS_NOT_FOUND) {
900902
throw new ResourceNotFoundException(
@@ -922,7 +924,7 @@ public Response apply(Request.Builder funcBuilder) {
922924

923925
try {
924926
ResponseBody body = response.body();
925-
MimeMultipart entity = body.contentLength() != 0 ?
927+
MimeMultipart entity = (body.contentLength() != 0) ?
926928
getEntity(body, MimeMultipart.class) : null;
927929
if (entity == null) return false;
928930

@@ -1501,6 +1503,7 @@ public Response apply(Request.Builder funcBuilder) {
15011503
}
15021504
};
15031505
Response response = sendRequestWithRetry(requestBldr, doPostFunction, null);
1506+
Objects.requireNonNull(response);
15041507
int status = response.code();
15051508
if (status == STATUS_FORBIDDEN) {
15061509
throw new ForbiddenUserException("User is not allowed to open transactions", extractErrorFields(response));
@@ -1510,12 +1513,14 @@ public Response apply(Request.Builder funcBuilder) {
15101513
getReasonPhrase(response), extractErrorFields(response));
15111514
}
15121515

1513-
String location = response.headers().get("Location");
1514-
List<ClientCookie> cookies = new ArrayList<>();
1516+
final String location = response.headers().get("Location");
1517+
1518+
final List<ClientCookie> cookies = new ArrayList<>();
15151519
for (String setCookie : response.headers(HEADER_SET_COOKIE)) {
15161520
ClientCookie cookie = parseClientCookie(requestBldr.build().url(), setCookie);
15171521
cookies.add(cookie);
15181522
}
1523+
15191524
closeResponse(response);
15201525
if (location == null) throw new MarkLogicInternalException("transaction open failed to provide location");
15211526
if (!location.contains("/")) {
@@ -2562,6 +2567,7 @@ public Response apply(Request.Builder funcBuilder) {
25622567
}
25632568
};
25642569
Response response = sendRequestWithRetry(requestBldr, doGetFunction, null);
2570+
Objects.requireNonNull(response);
25652571
int status = response.code();
25662572
if (status == STATUS_FORBIDDEN) {
25672573
throw new ForbiddenUserException("User is not allowed to read "
@@ -2749,6 +2755,7 @@ public Response apply(Request.Builder funcBuilder) {
27492755
}
27502756
};
27512757
Response response = sendRequestWithRetry(requestBldr, doDeleteFunction, null);
2758+
Objects.requireNonNull(response);
27522759
int status = response.code();
27532760
if (status == STATUS_FORBIDDEN) {
27542761
throw new ForbiddenUserException("User is not allowed to delete "
@@ -3181,6 +3188,7 @@ public Response apply(Request.Builder funcBuilder) {
31813188
};
31823189

31833190
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doPostFunction, resendableConsumer);
3191+
Objects.requireNonNull(response);
31843192
int status = response.code();
31853193
checkStatus(response, status, operation, "resource", path,
31863194
ResponseStatus.OK_OR_CREATED_OR_NO_CONTENT);
@@ -3712,6 +3720,7 @@ public RESTServiceResultIterator postMultipartForm(
37123720
Consumer<Boolean> resendableConsumer = null;
37133721

37143722
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doPostFunction, resendableConsumer);
3723+
Objects.requireNonNull(response);
37153724
int status = response.code();
37163725
checkStatus(response, status, "apply", "resource", path, ResponseStatus.OK_OR_CREATED_OR_NO_CONTENT);
37173726
return makeResults(OkHttpServiceResultIterator::new, reqlog, "apply", "resource", response);
@@ -3782,6 +3791,7 @@ private <U extends OkHttpResultIterator> U postIteratedResourceImpl(
37823791
);
37833792

37843793
Response response = sendRequestWithRetry(requestBldr, (transaction == null), doPostFunction, resendableConsumer);
3794+
Objects.requireNonNull(response);
37853795
checkStatus(response, response.code(), "apply", "resource", path, ResponseStatus.OK_OR_CREATED_OR_NO_CONTENT);
37863796

37873797
boolean shouldStreamResults = "eval".equalsIgnoreCase(path) || "invoke".equalsIgnoreCase(path);
@@ -4820,6 +4830,7 @@ public Response apply(Request.Builder funcBuilder) {
48204830
}
48214831
};
48224832
Response response = sendRequestWithRetry(requestBldr, doGetFunction, null);
4833+
Objects.requireNonNull(response);
48234834
int status = response.code();
48244835
if (status == STATUS_FORBIDDEN) {
48254836
throw new ForbiddenUserException(
@@ -5040,7 +5051,8 @@ public Response apply(Request.Builder funcBuilder) {
50405051
}
50415052
};
50425053
Response response = sendRequestWithRetry(requestBldr, doGetFunction, null);
5043-
int status = response.code();
5054+
Objects.requireNonNull(response);
5055+
final int status = response.code();
50445056
if (status == STATUS_FORBIDDEN) {
50455057
throw new ForbiddenUserException("User is not allowed to match",
50465058
extractErrorFields(response));
@@ -5618,9 +5630,11 @@ private void executeRequest(CallResponseImpl responseImpl) {
56185630

56195631
if (session != null) {
56205632
List<ClientCookie> cookies = new ArrayList<>();
5621-
for (String setCookie : response.headers(HEADER_SET_COOKIE)) {
5622-
ClientCookie cookie = parseClientCookie(requestBldr.build().url(), setCookie);
5623-
cookies.add(cookie);
5633+
if (response != null) {
5634+
for (String setCookie : response.headers(HEADER_SET_COOKIE)) {
5635+
ClientCookie cookie = parseClientCookie(requestBldr.build().url(), setCookie);
5636+
cookies.add(cookie);
5637+
}
56245638
}
56255639
((SessionStateImpl) session).setCookies(cookies);
56265640
}

0 commit comments

Comments
 (0)