diff --git a/marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/ContentExclusionUtil.java b/marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/ContentExclusionUtil.java index a2d5c4fb8..cd2ba9618 100644 --- a/marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/ContentExclusionUtil.java +++ b/marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/ContentExclusionUtil.java @@ -83,8 +83,11 @@ private static void removeNodeAtPointer(String uri, JsonNode rootNode, String js JsonNode parentNode = rootNode.at(parentPointer); if (parentNode.isObject()) { - String fieldName = pointer.last().getMatchingProperty(); - ((ObjectNode) parentNode).remove(fieldName); + JsonPointer lastSegment = pointer.last(); + if (lastSegment != null) { + String fieldName = lastSegment.getMatchingProperty(); + ((ObjectNode) parentNode).remove(fieldName); + } } else if (parentNode.isArray()) { logger.warn("Array element exclusion not supported for JSONPointer '{}'. " + "Consider excluding the entire array property instead.", jsonPointer); diff --git a/marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/IncrementalWriteFilter.java b/marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/IncrementalWriteFilter.java index 46dd06cd8..73f4fd5f9 100644 --- a/marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/IncrementalWriteFilter.java +++ b/marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/IncrementalWriteFilter.java @@ -152,7 +152,15 @@ protected final DocumentWriteSet filterDocuments(Context context, Function cookies = new ArrayList<>(); + final String location = response.headers().get("Location"); + + final List cookies = new ArrayList<>(); for (String setCookie : response.headers(HEADER_SET_COOKIE)) { ClientCookie cookie = parseClientCookie(requestBldr.build().url(), setCookie); cookies.add(cookie); } + closeResponse(response); if (location == null) throw new MarkLogicInternalException("transaction open failed to provide location"); if (!location.contains("/")) { @@ -2562,6 +2567,7 @@ public Response apply(Request.Builder funcBuilder) { } }; Response response = sendRequestWithRetry(requestBldr, doGetFunction, null); + Objects.requireNonNull(response); int status = response.code(); if (status == STATUS_FORBIDDEN) { throw new ForbiddenUserException("User is not allowed to read " @@ -2749,6 +2755,7 @@ public Response apply(Request.Builder funcBuilder) { } }; Response response = sendRequestWithRetry(requestBldr, doDeleteFunction, null); + Objects.requireNonNull(response); int status = response.code(); if (status == STATUS_FORBIDDEN) { throw new ForbiddenUserException("User is not allowed to delete " @@ -3181,6 +3188,7 @@ public Response apply(Request.Builder funcBuilder) { }; Response response = sendRequestWithRetry(requestBldr, (transaction == null), doPostFunction, resendableConsumer); + Objects.requireNonNull(response); int status = response.code(); checkStatus(response, status, operation, "resource", path, ResponseStatus.OK_OR_CREATED_OR_NO_CONTENT); @@ -3712,6 +3720,7 @@ public RESTServiceResultIterator postMultipartForm( Consumer resendableConsumer = null; Response response = sendRequestWithRetry(requestBldr, (transaction == null), doPostFunction, resendableConsumer); + Objects.requireNonNull(response); int status = response.code(); checkStatus(response, status, "apply", "resource", path, ResponseStatus.OK_OR_CREATED_OR_NO_CONTENT); return makeResults(OkHttpServiceResultIterator::new, reqlog, "apply", "resource", response); @@ -3782,6 +3791,7 @@ private U postIteratedResourceImpl( ); Response response = sendRequestWithRetry(requestBldr, (transaction == null), doPostFunction, resendableConsumer); + Objects.requireNonNull(response); checkStatus(response, response.code(), "apply", "resource", path, ResponseStatus.OK_OR_CREATED_OR_NO_CONTENT); boolean shouldStreamResults = "eval".equalsIgnoreCase(path) || "invoke".equalsIgnoreCase(path); @@ -4820,6 +4830,7 @@ public Response apply(Request.Builder funcBuilder) { } }; Response response = sendRequestWithRetry(requestBldr, doGetFunction, null); + Objects.requireNonNull(response); int status = response.code(); if (status == STATUS_FORBIDDEN) { throw new ForbiddenUserException( @@ -5040,7 +5051,8 @@ public Response apply(Request.Builder funcBuilder) { } }; Response response = sendRequestWithRetry(requestBldr, doGetFunction, null); - int status = response.code(); + Objects.requireNonNull(response); + final int status = response.code(); if (status == STATUS_FORBIDDEN) { throw new ForbiddenUserException("User is not allowed to match", extractErrorFields(response)); @@ -5618,9 +5630,11 @@ private void executeRequest(CallResponseImpl responseImpl) { if (session != null) { List cookies = new ArrayList<>(); - for (String setCookie : response.headers(HEADER_SET_COOKIE)) { - ClientCookie cookie = parseClientCookie(requestBldr.build().url(), setCookie); - cookies.add(cookie); + if (response != null) { + for (String setCookie : response.headers(HEADER_SET_COOKIE)) { + ClientCookie cookie = parseClientCookie(requestBldr.build().url(), setCookie); + cookies.add(cookie); + } } ((SessionStateImpl) session).setCookies(cookies); }