You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by mo...@apache.org on 2017/05/11 17:33:20 UTC
[18/39] nifi git commit: NIFI-1125 InvokeHTTP throws
NullPointerException
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/97d064ff
Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/97d064ff
Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/97d064ff
Branch: refs/heads/support/nifi-0.7.x
Commit: 97d064ff5c1bc2d6eee615aa39a59f909fc98a0a
Parents: 4f72e34
Author: Koji Kawamura <ij...@apache.org>
Authored: Tue Feb 7 11:08:06 2017 +0900
Committer: Mike Moser <mo...@apache.org>
Committed: Fri Feb 10 16:22:42 2017 -0500
----------------------------------------------------------------------
.../nifi/processors/standard/InvokeHTTP.java | 2 +-
.../processors/standard/TestInvokeHTTP.java | 29 ++++++++++++++++++++
2 files changed, 30 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/nifi/blob/97d064ff/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 8c5dc4d..6befbf4 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
@@ -460,7 +460,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/97d064ff/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 3f64c3c..29ec0bb 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
@@ -18,6 +18,7 @@ package org.apache.nifi.processors.standard;
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;
@@ -39,6 +40,8 @@ import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
public class TestInvokeHTTP extends TestInvokeHttpCommon {
@@ -208,4 +211,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));
+
+ }
}