From 4af868a4cf13be613d15b79e91b91dab9afa0d4e Mon Sep 17 00:00:00 2001 From: "godugu@progress.com" Date: Thu, 20 Aug 2026 07:53:36 -0700 Subject: [PATCH] MLE-32054: [java-client-api][polaris]Improper Resource Shutdown or --- .../datamovement/OpticExportListener.java | 17 +++++--- .../OpticExportToWriterListener.java | 43 ++++++++++--------- 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/OpticExportListener.java b/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/OpticExportListener.java index 79b46275d..f8813bae7 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/OpticExportListener.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/OpticExportListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. + * Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. */ package com.marklogic.client.example.cookbook.datamovement; @@ -18,6 +18,7 @@ import com.marklogic.client.expression.PlanBuilder; import com.marklogic.client.row.RowManager; import com.marklogic.client.row.RowRecord; +import com.marklogic.client.row.RowSet; /** * Takes in a Function which takes QueryBatch as argument and converts it into a @@ -74,12 +75,14 @@ public OpticExportListener(Function function, RowM public void processEvent(QueryBatch batch) { try { PlanBuilder.Plan exportPlan = exportFunction.apply(batch); - for (RowRecord record : rowManager.resultRows(exportPlan)) { - for (Consumer listener : opticExportListeners) { - try { - listener.accept(record); - } catch (Throwable t) { - logger.error("Exception thrown by an onRowRecordReady listener ", t); + try (RowSet rows = rowManager.resultRows(exportPlan)) { + for (RowRecord record : rows) { + for (Consumer listener : opticExportListeners) { + try { + listener.accept(record); + } catch (Throwable t) { + logger.error("Exception thrown by an onRowRecordReady listener ", t); + } } } } diff --git a/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/OpticExportToWriterListener.java b/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/OpticExportToWriterListener.java index fb3a07568..3bb2e00f7 100644 --- a/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/OpticExportToWriterListener.java +++ b/examples/src/main/java/com/marklogic/client/example/cookbook/datamovement/OpticExportToWriterListener.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. + * Copyright (c) 2010-2026 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved. */ package com.marklogic.client.example.cookbook.datamovement; @@ -20,6 +20,7 @@ import com.marklogic.client.expression.PlanBuilder.Plan; import com.marklogic.client.row.RowManager; import com.marklogic.client.row.RowRecord; +import com.marklogic.client.row.RowSet; /** * An extension of OpticExportListener which facilitates writing all row records @@ -92,28 +93,30 @@ public void processEvent(QueryBatch batch) { try { PlanBuilder.Plan exportPlan = exportFunction.apply(batch); synchronized (writer) { - for (RowRecord record : rowManager.resultRows(exportPlan)) { - try { - if (prefix != null) - writer.write(prefix); - if (outputListeners.size() > 0) { - for (OpticOutputListener listener : outputListeners) { - String output = null; - try { - output = listener.generateOutput(record); - } catch (Throwable t) { - logger.error("Exception thrown by an onGenerateOutput listener", t); + try (RowSet rows = rowManager.resultRows(exportPlan)) { + for (RowRecord record : rows) { + try { + if (prefix != null) + writer.write(prefix); + if (outputListeners.size() > 0) { + for (OpticOutputListener listener : outputListeners) { + String output = null; + try { + output = listener.generateOutput(record); + } catch (Throwable t) { + logger.error("Exception thrown by an onGenerateOutput listener", t); + } + if (output != null) + writer.write(output); } - if (output != null) - writer.write(output); + } else { + writer.write(record.toString()); } - } else { - writer.write(record.toString()); + if (suffix != null) + writer.write(suffix); + } catch (IOException e) { + throw new DataMovementException("Failed to write the Optic API records", e); } - if (suffix != null) - writer.write(suffix); - } catch (IOException e) { - throw new DataMovementException("Failed to write the Optic API records", e); } } }