Repository: nifi Updated Branches: refs/heads/master 3d3faada5 -> 9a638cc86
NIFI-1125 InvokeHTTP throws NullPointerException Added null check in onPropertyModified to avoid NPE. This closes #1477. Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/9a638cc8 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/9a638cc8 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/9a638cc8 Branch: refs/heads/master Commit: 9a638cc865518aef71ee34330c5192786bbfff44 Parents: 3d3faad Author: Koji Kawamura <[email protected]> Authored: Tue Feb 7 11:08:06 2017 +0900 Committer: Pierre Villard <[email protected]> Committed: Tue Feb 7 09:06:43 2017 +0100 ---------------------------------------------------------------------- .../nifi/processors/standard/InvokeHTTP.java | 2 +- .../processors/standard/TestInvokeHTTP.java | 30 ++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/9a638cc8/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java index c3d7fe9..c95b639 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/InvokeHTTP.java @@ -466,7 +466,7 @@ public final class InvokeHTTP extends AbstractProcessor { } else { // compile the attributes-to-send filter pattern if (PROP_ATTRIBUTES_TO_SEND.getName().equalsIgnoreCase(descriptor.getName())) { - if (newValue.isEmpty()) { + if (newValue == null || newValue.isEmpty()) { regexAttributesToSend = null; } else { final String trimmedValue = StringUtils.trimToEmpty(newValue); http://git-wip-us.apache.org/repos/asf/nifi/blob/9a638cc8/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java index fc0570a..a6b798b 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestInvokeHTTP.java @@ -34,10 +34,14 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; +import java.lang.reflect.Field; import java.net.URL; import java.util.HashMap; import java.util.Map; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + public class TestInvokeHTTP extends TestInvokeHttpCommon { @@ -232,4 +236,30 @@ public class TestInvokeHTTP extends TestInvokeHttpCommon { } } } + + @Test + public void testOnPropertyModified() throws Exception { + final InvokeHTTP processor = new InvokeHTTP(); + final Field regexAttributesToSendField = InvokeHTTP.class.getDeclaredField("regexAttributesToSend"); + regexAttributesToSendField.setAccessible(true); + + assertNull(regexAttributesToSendField.get(processor)); + + // Set Attributes to Send. + processor.onPropertyModified(InvokeHTTP.PROP_ATTRIBUTES_TO_SEND, null, "uuid"); + assertNotNull(regexAttributesToSendField.get(processor)); + + // Null clear Attributes to Send. NIFI-1125: Throws NullPointerException. + processor.onPropertyModified(InvokeHTTP.PROP_ATTRIBUTES_TO_SEND, "uuid", null); + assertNull(regexAttributesToSendField.get(processor)); + + // Set Attributes to Send. + processor.onPropertyModified(InvokeHTTP.PROP_ATTRIBUTES_TO_SEND, null, "uuid"); + assertNotNull(regexAttributesToSendField.get(processor)); + + // Clear Attributes to Send with empty string. + processor.onPropertyModified(InvokeHTTP.PROP_ATTRIBUTES_TO_SEND, "uuid", ""); + assertNull(regexAttributesToSendField.get(processor)); + + } }
