markap14 commented on code in PR #8943:
URL: https://github.com/apache/nifi/pull/8943#discussion_r1633832101


##########
nifi-extension-bundles/nifi-py4j-bundle/nifi-py4j-bridge/src/main/java/org/apache/nifi/python/processor/RecordTransformProxy.java:
##########
@@ -264,13 +264,22 @@ private void writeResult(final RecordTransformResult 
result, final Map<RecordGro
             final FlowFile destinationFlowFile = 
session.create(originalFlowFile);
 
             final RecordSetWriter writer;
+            OutputStream out = null;
             try {
-                final OutputStream out = session.write(destinationFlowFile);
+                out = session.write(destinationFlowFile);
                 final Map<String, String> originalAttributes = 
originalFlowFile.getAttributes();
                 final RecordSchema writeSchema = 
writerFactory.getSchema(originalAttributes, transformed.getSchema());
                 writer = writerFactory.createWriter(getLogger(), writeSchema, 
out, originalAttributes);
                 writer.beginRecordSet();
             } catch (final Exception e) {
+                // If we failed to create the RecordSetWriter, ensure that we 
close the Output Stream
+                if (out != null) {
+                    try {
+                        out.close();
+                    } catch (final IOException ignore) {
+                    }
+                }

Review Comment:
   Good suggestion, thanks!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to