Skip to content

MLE-29977: Fixed Polaris reported CWE-404 - #1987

Open
hmadala001 wants to merge 2 commits into
developfrom
MLE-29977-resource-shutdown
Open

hmadala001 wants to merge 2 commits into
developfrom
MLE-29977-resource-shutdown

Conversation

@hmadala001

Copy link
Copy Markdown

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Regression tests are missing for both changed InputStream overloads to verify underlying input cleanup when unconsumed or partially consumed streams are closed and UncheckedIOException when InputStream.close() fails.

1 open issue
What changed in this PR

This PR addresses Polaris-reported CWE-404 resource cleanup issues in the Java client library and its Jackson example.

Changes:

  • Use try-with-resources for JSON generators and the example input stream.
  • Close internally created JSON parsers when splitter streams are closed or stream setup fails.
File Description
marklogic-client-api/​src/​main/​java/​com/​marklogic/​client/​pojo/​util/​GenerateIndexConfig.java Ensure the configuration generator closes on failure.
marklogic-client-api/​src/​main/​java/​com/​marklogic/​client/​io/​JacksonParserHandle.java Ensure generators close in both write implementations.
marklogic-client-api/​src/​main/​java/​com/​marklogic/​client/​datamovement/​JSONSplitter.java Add parser cleanup handlers and setup-failure cleanup.
examples/​src/​main/​java/​com/​marklogic/​client/​example/​handle/​JacksonHandleExample.java Scope the example input stream with try-with-resources.

Review effort: Balanced

JsonParser jsonParser = new JsonFactory().createParser(input);
return split(jsonParser);
try {
return split(jsonParser).onClose(() -> closeParser(jsonParser));
@prgs-rsingh

Copy link
Copy Markdown

The try-with-resources and Stream.onClose(...) changes look good! A few items to address so CI passes and the new cleanup path is covered:

  1. CI — Copyright Headers (Validate Copyright Headers check failing):
    Please update the copyright header year from 2010-2025 to 2010-2026 in the 4 modified files (JacksonHandleExample.java, JSONSplitter.java, JacksonParserHandle.java, and GenerateIndexConfig.java).

  2. CI — PR Title (JIRA ID Validator check failing):
    Please prefix the PR title with the Jira ID: MLE-29977: Fixed Polaris reported CWE-404.

  3. Remaining JsonGenerator in JSONSplitter.Visitor.serialize (JSONSplitter.java lines 275–279):
    While fixing CWE-404 in JSONSplitter.java, Visitor.serialize(JsonParser) also creates a JsonGenerator without try-with-resources:

    try (StringWriter stringWriter = new StringWriter();
         JsonGenerator jsonGenerator = new JsonFactory().createGenerator(stringWriter)) {
        jsonGenerator.copyCurrentStructure(containerParser);
        jsonGenerator.flush();
        return stringWriter.toString();
    }
  4. Unit test for JSONSplitter stream closure (JSONSplitterTest.java):
    Since existing tests in JSONSplitterTest don't close the returned Stream, please add a unit test that wraps splitter.split(inputStream) and splitter.splitWriteOperations(inputStream) in try (Stream<...> stream = ...) (e.g., consuming only the first element via stream.findFirst()) and asserts that the underlying InputStream was closed when the Stream closed.

@hmadala001 hmadala001 changed the title Fixed Polaris reported CWE-404 MLE-29977: Fixed Polaris reported CWE-404 Nov 10, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hmadala001

Copy link
Copy Markdown
Author

The try-with-resources and Stream.onClose(...) changes look good! A few items to address so CI passes and the new cleanup path is covered:

  1. CI — Copyright Headers (Validate Copyright Headers check failing):
    Please update the copyright header year from 2010-2025 to 2010-2026 in the 4 modified files (JacksonHandleExample.java, JSONSplitter.java, JacksonParserHandle.java, and GenerateIndexConfig.java).
  2. CI — PR Title (JIRA ID Validator check failing):
    Please prefix the PR title with the Jira ID: MLE-29977: Fixed Polaris reported CWE-404.
  3. Remaining JsonGenerator in JSONSplitter.Visitor.serialize (JSONSplitter.java lines 275–279):
    While fixing CWE-404 in JSONSplitter.java, Visitor.serialize(JsonParser) also creates a JsonGenerator without try-with-resources:
    try (StringWriter stringWriter = new StringWriter();
         JsonGenerator jsonGenerator = new JsonFactory().createGenerator(stringWriter)) {
        jsonGenerator.copyCurrentStructure(containerParser);
        jsonGenerator.flush();
        return stringWriter.toString();
    }
  4. Unit test for JSONSplitter stream closure (JSONSplitterTest.java):
    Since existing tests in JSONSplitterTest don't close the returned Stream, please add a unit test that wraps splitter.split(inputStream) and splitter.splitWriteOperations(inputStream) in try (Stream<...> stream = ...) (e.g., consuming only the first element via stream.findFirst()) and asserts that the underlying InputStream was closed when the Stream closed.

fixed

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