Skip to content

MLE-32054: [java-client-api][polaris]Improper Resource Shutdown or Release - #1970

Merged
rjdew-progress merged 1 commit into
developfrom
MLE-32054
Aug 20, 2026
Merged

MLE-32054: [java-client-api][polaris]Improper Resource Shutdown or Release#1970
rjdew-progress merged 1 commit into
developfrom
MLE-32054

Conversation

@ngodugu-marklogic

Copy link
Copy Markdown

PR Description

Fix CWE-404 resource leak in OpticExportListener and OpticExportToWriterListener

Problem

RowSet implements Closeable (it holds an open HTTP response stream from MarkLogic). Both OpticExportListener.processEvent() and OpticExportToWriterListener.processEvent() iterated over rowManager.resultRows(exportPlan) using a plain for-each loop, which never closes the RowSet. This leaks the underlying connection on every batch processed, reducing future resource availability (Polaris CWE-404, Risk Score 80).

Fix

Wrapped rowManager.resultRows() in a try-with-resources block in both classes, ensuring the RowSet is closed on all exit paths including exceptions. This matches the pattern already established in RowTemplate.java.

Files Changed

  1. examples/src/main/java/.../OpticExportListener.java — added RowSet import; processEvent now uses try-with-resources
  2. examples/src/main/java/.../OpticExportToWriterListener.java — same; try-with-resources wraps the RowSet inside the existing synchronized (writer) block

Validation

  1. Confirmed RowSet extends Closeable (RowSet.java)
  2. Verified identical fix pattern is used in RowTemplate.java
  3. ./gradlew examples:compileJava passes with no warnings

Copilot AI lite review requested due to automatic review settings August 20, 2026 14:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a CWE-404 resource leak in the examples module’s Optic Data Movement listeners by ensuring the RowSet<RowRecord> returned from RowManager.resultRows(...) is always closed (it holds an open HTTP response stream).

Changes:

  • Wraps rowManager.resultRows(exportPlan) in try-with-resources in OpticExportListener.processEvent to reliably close the RowSet.
  • Applies the same try-with-resources pattern in OpticExportToWriterListener.processEvent (inside the existing synchronized (writer) block).
  • Adds the necessary RowSet imports.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/OpticExportListener.java Ensures RowSet is closed via try-with-resources during row iteration to prevent connection/resource leaks.
examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/OpticExportToWriterListener.java Ensures RowSet is closed via try-with-resources while exporting rows to a Writer, preventing per-batch connection/resource leaks.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@rjdew-progress
rjdew-progress merged commit 6b79717 into develop Aug 20, 2026
4 checks passed
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