Skip to content

Conversation

@rjrudin
Copy link
Contributor

@rjrudin rjrudin commented Jan 16, 2026

Most of these already existed in OkHttpServices, but Polaris decided to report them recently

Copilot AI review requested due to automatic review settings January 16, 2026 16:23
@github-actions
Copy link

github-actions bot commented Jan 16, 2026

Copyright Validation Results
Total: 3 | Passed: 3 | Failed: 0 | Skipped: 0 | at: 2026-01-16 16:48:31 UTC | commit: ff07804

✅ Valid Files

  • marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/ContentExclusionUtil.java
  • marklogic-client-api/src/main/java/com/marklogic/client/datamovement/filter/IncrementalWriteFilter.java
  • marklogic-client-api/src/main/java/com/marklogic/client/impl/OkHttpServices.java

✅ All files have valid copyright headers!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Polaris static analysis issues by adding null checks throughout the codebase. The changes focus on defensive programming to prevent potential null pointer exceptions, particularly when handling HTTP responses and JSON operations.

Changes:

  • Added null checks for HTTP response objects before accessing their methods
  • Added null checks for JSON pointer operations and serialized content
  • Added null check for consumer callback before invocation

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
OkHttpServices.java Added defensive null checks for HTTP response objects and response body before accessing their properties and methods
IncrementalWriteFilter.java Added null checks for serialized content and consumer callback to prevent null pointer exceptions
ContentExclusionUtil.java Added null check for JSON pointer last segment before accessing its properties

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 622 to 623
int status = response != null ? response.code() : 0;
if (status == STATUS_NOT_FOUND) {
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When response is null, status is set to 0, but the subsequent logic continues to check specific status codes and may attempt to extract error fields from the null response. Consider adding an early return or throwing an exception when response is null, or ensure that all downstream methods like extractErrorFields() handle null responses gracefully.

Copilot uses AI. Check for mistakes.
Comment on lines 663 to 664
ResponseBody body = response != null ? response.body() : null;
Object entity = (body != null && body.contentLength() != 0) ? getEntity(body, as) : null;
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The null check for response is repeated multiple times in this method. Since the response is checked at line 622 and subsequent logic depends on it being non-null (line 624 throws an exception for STATUS_NOT_FOUND), the additional null checks at lines 651, 663 become redundant. Consider adding a single null check early in the method or documenting why response could legitimately be null at these points despite earlier checks.

Copilot uses AI. Check for mistakes.
Comment on lines 1517 to 1519
final String location = response != null ? response.headers().get("Location") : null;

final List<ClientCookie> cookies = new ArrayList<>();
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The location and cookies variables are marked as final but their values are only used after the response null check. Since they're declared final, consider moving the declarations inside the null check block or removing the final modifier if they need to be conditionally initialized.

Suggested change
final String location = response != null ? response.headers().get("Location") : null;
final List<ClientCookie> cookies = new ArrayList<>();
String location = response != null ? response.headers().get("Location") : null;
List<ClientCookie> cookies = new ArrayList<>();

Copilot uses AI. Check for mistakes.
}

closeResponse(response);
if (location == null) throw new MarkLogicInternalException("transaction open failed to provide location");
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When response is null, location will be null (line 1517), leading to this exception being thrown. However, the error message 'transaction open failed to provide location' is misleading when the actual issue is a null response. Consider checking for null response explicitly before this line and providing a more accurate error message.

Copilot uses AI. Check for mistakes.
ResponseBody body = response.body();
T entity = body.contentLength() != 0 ? getEntity(body, as) : null;
ResponseBody body = response != null ? response.body() : null;
T entity = body != null && body.contentLength() != 0 ? getEntity(body, as) : null;
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition 'body != null && body.contentLength() != 0' is repeated in multiple locations (lines 664, 927, 2586, 4846, 5065). Consider extracting this logic into a helper method like 'hasContent(ResponseBody body)' to improve maintainability and ensure consistency.

Copilot uses AI. Check for mistakes.
Comment on lines +157 to +158
// Not sure if the doc can have null content - possibly for a naked properties document? - but if it
// does, just include it in the write set.
Copy link

Copilot AI Jan 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment expresses uncertainty about when serializedContent can be null ('Not sure if the doc can have null content'). This uncertainty should be resolved through code analysis or documentation review. Update the comment to either explain the specific scenarios where null content occurs or remove the speculative language if the behavior is now understood.

Suggested change
// Not sure if the doc can have null content - possibly for a naked properties document? - but if it
// does, just include it in the write set.
// If the content cannot be serialized (serializeContent returned null), include the document in the write set unchanged.

Copilot uses AI. Check for mistakes.
@rjrudin rjrudin force-pushed the feature/polaris branch 2 times, most recently from 09a5b1e to 1d66359 Compare January 16, 2026 16:46
Most of these already existed in OkHttpServices, but Polaris decided to report them recently
@rjrudin rjrudin merged commit 79887f0 into develop Jan 16, 2026
4 checks passed
@rjrudin rjrudin deleted the feature/polaris branch January 16, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants