NIFI-1125 InvokeHTTP throws NullPointerException

Added null check in onPropertyModified to avoid NPE.

This closes #1477.
This commit is contained in:
Koji Kawamura 2017-02-07 11:08:06 +09:00 committed by Pierre Villard
parent 3d3faada5c
commit 9a638cc865
2 changed files with 31 additions and 1 deletions

View File

@ -466,7 +466,7 @@ public final class InvokeHTTP extends AbstractProcessor {
} else { } else {
// compile the attributes-to-send filter pattern // compile the attributes-to-send filter pattern
if (PROP_ATTRIBUTES_TO_SEND.getName().equalsIgnoreCase(descriptor.getName())) { if (PROP_ATTRIBUTES_TO_SEND.getName().equalsIgnoreCase(descriptor.getName())) {
if (newValue.isEmpty()) { if (newValue == null || newValue.isEmpty()) {
regexAttributesToSend = null; regexAttributesToSend = null;
} else { } else {
final String trimmedValue = StringUtils.trimToEmpty(newValue); final String trimmedValue = StringUtils.trimToEmpty(newValue);

View File

@ -34,10 +34,14 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
public class TestInvokeHTTP extends TestInvokeHttpCommon { 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));
}
} }