NIFI-3330 Replaced two instances of multiple calls to getter methods during request attribute retrieval with a single call saved to a local variable to prevent null pointer exceptions during multiple invocations of a getter method.

This closes #1415.

Signed-off-by: Bryan Rosander <brosander@apache.org>
This commit is contained in:
Jeff Storck 2017-01-13 17:03:24 -05:00 committed by Bryan Rosander
parent 4d533a99b3
commit def4918af0
No known key found for this signature in database
GPG Key ID: 2065F38F3FF65D23
1 changed files with 7 additions and 5 deletions

View File

@ -38,6 +38,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
import javax.servlet.DispatcherType;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -512,8 +513,9 @@ public class HandleHttpRequest extends AbstractProcessor {
putAttribute(attributes, "http.method", request.getMethod()); putAttribute(attributes, "http.method", request.getMethod());
putAttribute(attributes, "http.local.addr", request.getLocalAddr()); putAttribute(attributes, "http.local.addr", request.getLocalAddr());
putAttribute(attributes, HTTPUtils.HTTP_LOCAL_NAME, request.getLocalName()); putAttribute(attributes, HTTPUtils.HTTP_LOCAL_NAME, request.getLocalName());
if (request.getQueryString() != null) { final String queryString = request.getQueryString();
putAttribute(attributes, "http.query.string", URLDecoder.decode(request.getQueryString(), charset)); if (queryString != null) {
putAttribute(attributes, "http.query.string", URLDecoder.decode(queryString, charset));
} }
putAttribute(attributes, HTTPUtils.HTTP_REMOTE_HOST, request.getRemoteHost()); putAttribute(attributes, HTTPUtils.HTTP_REMOTE_HOST, request.getRemoteHost());
putAttribute(attributes, "http.remote.addr", request.getRemoteAddr()); putAttribute(attributes, "http.remote.addr", request.getRemoteAddr());
@ -523,8 +525,9 @@ public class HandleHttpRequest extends AbstractProcessor {
putAttribute(attributes, "http.auth.type", request.getAuthType()); putAttribute(attributes, "http.auth.type", request.getAuthType());
putAttribute(attributes, "http.requested.session.id", request.getRequestedSessionId()); putAttribute(attributes, "http.requested.session.id", request.getRequestedSessionId());
if (request.getDispatcherType() != null) { final DispatcherType dispatcherType = request.getDispatcherType();
putAttribute(attributes, "http.dispatcher.type", request.getDispatcherType().name()); if (dispatcherType != null) {
putAttribute(attributes, "http.dispatcher.type", dispatcherType.name());
} }
putAttribute(attributes, "http.character.encoding", request.getCharacterEncoding()); putAttribute(attributes, "http.character.encoding", request.getCharacterEncoding());
putAttribute(attributes, "http.locale", request.getLocale()); putAttribute(attributes, "http.locale", request.getLocale());
@ -552,7 +555,6 @@ public class HandleHttpRequest extends AbstractProcessor {
} }
} }
final String queryString = request.getQueryString();
if (queryString != null) { if (queryString != null) {
final String[] params = URL_QUERY_PARAM_DELIMITER.split(queryString); final String[] params = URL_QUERY_PARAM_DELIMITER.split(queryString);
for (final String keyValueString : params) { for (final String keyValueString : params) {