From a61a4c2b5878f53777df8df1dd91a78629ba23bb Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Tue, 14 Apr 2020 17:08:49 -0400 Subject: [PATCH] NIFI-7347: Fixed NullPointerException that can happen if a bin is merged due to timeout and has no records Signed-off-by: Pierre Villard This closes #4210. --- .../processors/standard/merge/RecordBin.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/merge/RecordBin.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/merge/RecordBin.java index c3dbbaa1f5..b49fc2aa89 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/merge/RecordBin.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/merge/RecordBin.java @@ -124,18 +124,18 @@ public class RecordBin { logger.debug("Migrating id={} to {}", new Object[] {flowFile.getId(), this}); + if (recordWriter == null) { + final OutputStream rawOut = session.write(merged); + logger.debug("Created OutputStream using session {} for {}", new Object[] {session, this}); + + this.out = new ByteCountingOutputStream(rawOut); + + recordWriter = writerFactory.createWriter(logger, recordReader.getSchema(), out, flowFile); + recordWriter.beginRecordSet(); + } + Record record; while ((record = recordReader.nextRecord()) != null) { - if (recordWriter == null) { - final OutputStream rawOut = session.write(merged); - logger.debug("Created OutputStream using session {} for {}", new Object[] {session, this}); - - this.out = new ByteCountingOutputStream(rawOut); - - recordWriter = writerFactory.createWriter(logger, record.getSchema(), out, flowFile); - recordWriter.beginRecordSet(); - } - recordWriter.write(record); recordCount++; }