From 5764e892933f3fac958b39fe2c9a3cfde8afd59e Mon Sep 17 00:00:00 2001 From: Bryan Bende Date: Tue, 22 Sep 2015 13:19:15 -0400 Subject: [PATCH] NIFI-975 Fixing NullPointerException when one of the delimiters is not provided when using the Text strategy --- .../processors/standard/MergeContent.java | 5 ++++- .../processors/standard/TestMergeContent.java | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/MergeContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/MergeContent.java index c8f9bbe07e..e9258df743 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/MergeContent.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/MergeContent.java @@ -641,7 +641,10 @@ public class MergeContent extends BinFiles { if (wrapper != null) { final FlowFile flowFile = wrapper.getFlowFile(); if (flowFile != null) { - property = context.getProperty(descriptor).evaluateAttributeExpressions(flowFile).getValue().getBytes(); + final String value = context.getProperty(descriptor).evaluateAttributeExpressions(flowFile).getValue(); + if (value != null) { + property = value.getBytes(); + } } } } diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java index c53c488bb9..cd06ba060d 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestMergeContent.java @@ -256,6 +256,27 @@ public class TestMergeContent { bundle.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/plain-text"); } + @Test + public void testSimpleBinaryConcatWithTextDelimitersHeaderOnly() throws IOException, InterruptedException { + final TestRunner runner = TestRunners.newTestRunner(new MergeContent()); + runner.setProperty(MergeContent.MAX_BIN_AGE, "1 sec"); + runner.setProperty(MergeContent.MERGE_FORMAT, MergeContent.MERGE_FORMAT_CONCAT); + runner.setProperty(MergeContent.DELIMITER_STRATEGY, MergeContent.DELIMITER_STRATEGY_TEXT); + runner.setProperty(MergeContent.HEADER, "@"); + + createFlowFiles(runner); + runner.run(); + + runner.assertQueueEmpty(); + runner.assertTransferCount(MergeContent.REL_MERGED, 1); + runner.assertTransferCount(MergeContent.REL_FAILURE, 0); + runner.assertTransferCount(MergeContent.REL_ORIGINAL, 3); + + final MockFlowFile bundle = runner.getFlowFilesForRelationship(MergeContent.REL_MERGED).get(0); + bundle.assertContentEquals("@Hello, World!".getBytes("UTF-8")); + bundle.assertAttributeEquals(CoreAttributes.MIME_TYPE.key(), "application/plain-text"); + } + @Test public void testSimpleBinaryConcatWithFileDelimiters() throws IOException, InterruptedException { final TestRunner runner = TestRunners.newTestRunner(new MergeContent());