Skip to content

Conversation

@SiddharthMaheshB
Copy link

As part of Polaris Null Pointer Dereference issues cleanup, I have added null checks for the conf.getStrings() method in the following files:

    InternalUtilities.java
    PermissionUtil.java
    RDFReader.java
    InputType.java
    ThreadManager.java
    TransformOutputFormat.java
    ContentOutputFormat.java

SameeraPriyathamTadikonda and others added 28 commits July 17, 2025 12:51
Co-authored-by: Abika Santhosh Kumar <asanthos@rh8-asanthos-03.bedford.progress.com>
Copilot AI review requested due to automatic review settings February 9, 2026 06:43
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

Adds defensive checks around Configuration#getStrings(...) results to avoid null pointer dereferences during host resolution/config parsing across MapReduce + Content Pump components.

Changes:

  • Add null/empty-array validation for INPUT_HOST / OUTPUT_HOST before indexing [0].
  • Fail fast with IllegalArgumentException when required host lists are missing.
  • Apply the pattern across utilities, readers, formats, and thread management.

Reviewed changes

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

Show a summary per file
File Description
src/main/java/com/marklogic/mapreduce/utilities/InternalUtilities.java Guards getStrings(INPUT_HOST) before indexing to avoid NPE.
src/main/java/com/marklogic/mapreduce/ContentOutputFormat.java Validates OUTPUT_HOST when restrictHosts is enabled.
src/main/java/com/marklogic/contentpump/utilities/PermissionUtil.java Validates OUTPUT_HOST before selecting first host for session creation.
src/main/java/com/marklogic/contentpump/TransformOutputFormat.java Validates OUTPUT_HOST before attempting to query MIME types.
src/main/java/com/marklogic/contentpump/ThreadManager.java Validates OUTPUT_HOST list before iterating for host checks.
src/main/java/com/marklogic/contentpump/RDFReader.java Validates OUTPUT_HOST before selecting first host for permissions initialization.
src/main/java/com/marklogic/contentpump/InputType.java Validates OUTPUT_HOST before iterating through hosts for connection attempts.

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

" is not specified.");
}
String host = hosts[0];

Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

This change prevents NPE on a null/empty array, but it also removes the previous validation that hosts[0] itself is non-null/non-empty. As a result, a config like INPUT_HOST= (or an array containing null) will pass the new guard and can still fail later (or attempt to connect with an invalid hostname). Consider restoring a value-level check (e.g., null/blank after trimming) for hosts[0], or switch to a trimmed-string API and validate the first entry.

Suggested change
if (host == null || host.trim().isEmpty()) {
throw new IllegalArgumentException(INPUT_HOST +
" is not specified.");
}

Copilot uses AI. Check for mistakes.
Comment on lines +562 to 563
}
for (String host : hosts) {
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The new guard ensures the array exists, but individual entries may still be blank/whitespace (or null), which can cause connection attempts with invalid hostnames inside the loop. Add validation inside the loop (or pre-filter/normalize the array) to reject/skip empty hosts deterministically.

Suggested change
}
for (String host : hosts) {
}
List<String> validHosts = new ArrayList<String>();
for (String host : hosts) {
if (host != null && !host.trim().isEmpty()) {
validHosts.add(host);
}
}
if (validHosts.isEmpty()) {
throw new IllegalArgumentException(MarkLogicConstants.OUTPUT_HOST +
" does not contain any valid non-empty host values.");
}
for (String host : validHosts) {

Copilot uses AI. Check for mistakes.
Comment on lines +82 to +88
String[] hosts = conf.getStrings(MarkLogicConstants.OUTPUT_HOST);
if (hosts == null || hosts.length == 0) {
throw new IllegalArgumentException(MarkLogicConstants.OUTPUT_HOST +
" is not specified.");
}
cs = InternalUtilities.getOutputContentSource(conf,
conf.getStrings(MarkLogicConstants.OUTPUT_HOST)[0]);
hosts[0]);
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

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

The same getStrings(...) null/length check + identical exception message is now repeated across several files in this PR. To reduce duplication and keep host-validation semantics consistent (including trimming/blank checks), consider extracting a shared helper (e.g., in InternalUtilities) that returns a validated host list (or first host) and throws a consistent error when missing/invalid.

Copilot uses AI. Check for mistakes.
@abika5 abika5 requested review from DarrenJAN and abika5 February 9, 2026 21:52
@SiddharthMaheshB SiddharthMaheshB changed the base branch from main to develop February 10, 2026 04:46
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.

4 participants