Merge pull request #5046 from eclipse/jetty-10.0.x-4985-AttributeNameSet

Issue #4985 - fix NPE related to use of Attributes.Wrapper getAttributeNameSet() Jetty 10
This commit is contained in:
Lachlan 2020-07-16 08:51:56 +10:00 committed by GitHub
commit cadaf87583
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 27 deletions

View File

@ -28,16 +28,19 @@ class AsyncAttributes extends Attributes.Wrapper
{ {
private final String _requestURI; private final String _requestURI;
private final String _contextPath; private final String _contextPath;
private final String _pathInContext; private final ServletPathMapping _mapping;
private ServletPathMapping _mapping;
private final String _queryString; private final String _queryString;
private final String _servletPath;
private final String _pathInfo;
public AsyncAttributes(Attributes attributes, String requestUri, String contextPath, String pathInContext, ServletPathMapping mapping, String queryString) public AsyncAttributes(Attributes attributes, String requestUri, String contextPath, String pathInContext, ServletPathMapping mapping, String queryString)
{ {
super(attributes); super(attributes);
_requestURI = requestUri; _requestURI = requestUri;
_contextPath = contextPath; _contextPath = contextPath;
_pathInContext = pathInContext; _servletPath = mapping == null ? null : mapping.getServletPath();
_pathInfo = mapping == null ? pathInContext : mapping.getPathInfo();
_mapping = mapping; _mapping = mapping;
_queryString = queryString; _queryString = queryString;
} }
@ -52,9 +55,9 @@ class AsyncAttributes extends Attributes.Wrapper
case AsyncContext.ASYNC_CONTEXT_PATH: case AsyncContext.ASYNC_CONTEXT_PATH:
return _contextPath; return _contextPath;
case AsyncContext.ASYNC_SERVLET_PATH: case AsyncContext.ASYNC_SERVLET_PATH:
return _mapping == null ? null : _mapping.getServletPath(); return _servletPath;
case AsyncContext.ASYNC_PATH_INFO: case AsyncContext.ASYNC_PATH_INFO:
return _mapping == null ? _pathInContext : _mapping.getPathInfo(); return _pathInfo;
case AsyncContext.ASYNC_QUERY_STRING: case AsyncContext.ASYNC_QUERY_STRING:
return _queryString; return _queryString;
case AsyncContext.ASYNC_MAPPING: case AsyncContext.ASYNC_MAPPING:
@ -68,11 +71,17 @@ class AsyncAttributes extends Attributes.Wrapper
public Set<String> getAttributeNameSet() public Set<String> getAttributeNameSet()
{ {
Set<String> set = new HashSet<>(super.getAttributeNameSet()); Set<String> set = new HashSet<>(super.getAttributeNameSet());
if (_requestURI != null)
set.add(AsyncContext.ASYNC_REQUEST_URI); set.add(AsyncContext.ASYNC_REQUEST_URI);
if (_contextPath != null)
set.add(AsyncContext.ASYNC_CONTEXT_PATH); set.add(AsyncContext.ASYNC_CONTEXT_PATH);
if (_servletPath != null)
set.add(AsyncContext.ASYNC_SERVLET_PATH); set.add(AsyncContext.ASYNC_SERVLET_PATH);
if (_pathInfo != null)
set.add(AsyncContext.ASYNC_PATH_INFO); set.add(AsyncContext.ASYNC_PATH_INFO);
if (_queryString != null)
set.add(AsyncContext.ASYNC_QUERY_STRING); set.add(AsyncContext.ASYNC_QUERY_STRING);
if (_mapping != null)
set.add(AsyncContext.ASYNC_MAPPING); set.add(AsyncContext.ASYNC_MAPPING);
return set; return set;
} }

View File

@ -26,6 +26,7 @@ import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.ServletRequest; import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletMapping;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
@ -244,7 +245,8 @@ public class Dispatcher implements RequestDispatcher
{ {
private final String _requestURI; private final String _requestURI;
private final String _contextPath; private final String _contextPath;
private final String _pathInContext; private final String _servletPath;
private final String _pathInfo;
private final ServletPathMapping _servletPathMapping; private final ServletPathMapping _servletPathMapping;
private final String _query; private final String _query;
@ -253,9 +255,11 @@ public class Dispatcher implements RequestDispatcher
super(attributes); super(attributes);
_requestURI = requestURI; _requestURI = requestURI;
_contextPath = contextPath; _contextPath = contextPath;
_pathInContext = pathInContext;
_servletPathMapping = mapping; _servletPathMapping = mapping;
_query = query; _query = query;
_pathInfo = _servletPathMapping == null ? pathInContext : _servletPathMapping.getPathInfo();
_servletPath = _servletPathMapping == null ? null : _servletPathMapping.getServletPath();
} }
@Override @Override
@ -266,11 +270,11 @@ public class Dispatcher implements RequestDispatcher
switch (key) switch (key)
{ {
case FORWARD_PATH_INFO: case FORWARD_PATH_INFO:
return _servletPathMapping == null ? _pathInContext : _servletPathMapping.getPathInfo(); return _pathInfo;
case FORWARD_REQUEST_URI: case FORWARD_REQUEST_URI:
return _requestURI; return _requestURI;
case FORWARD_SERVLET_PATH: case FORWARD_SERVLET_PATH:
return _servletPathMapping == null ? null : _servletPathMapping.getServletPath(); return _servletPath;
case FORWARD_CONTEXT_PATH: case FORWARD_CONTEXT_PATH:
return _contextPath; return _contextPath;
case FORWARD_QUERY_STRING: case FORWARD_QUERY_STRING:
@ -302,11 +306,17 @@ public class Dispatcher implements RequestDispatcher
if (_named == null) if (_named == null)
{ {
if (_pathInfo != null)
set.add(FORWARD_PATH_INFO); set.add(FORWARD_PATH_INFO);
if (_requestURI != null)
set.add(FORWARD_REQUEST_URI); set.add(FORWARD_REQUEST_URI);
if (_servletPath != null)
set.add(FORWARD_SERVLET_PATH); set.add(FORWARD_SERVLET_PATH);
if (_contextPath != null)
set.add(FORWARD_CONTEXT_PATH); set.add(FORWARD_CONTEXT_PATH);
if (_servletPathMapping != null)
set.add(FORWARD_MAPPING); set.add(FORWARD_MAPPING);
if (_query != null)
set.add(FORWARD_QUERY_STRING); set.add(FORWARD_QUERY_STRING);
} }
@ -426,13 +436,25 @@ public class Dispatcher implements RequestDispatcher
set.add(name); set.add(name);
} }
// We can't assign these in the constructor because the ServletPathMapping hasn't been set by the ServletHandler.
String pathInfo = (String)getAttribute(INCLUDE_PATH_INFO);
String servletPath = (String)getAttribute(INCLUDE_SERVLET_PATH);
String contextPath = (String)getAttribute(INCLUDE_CONTEXT_PATH);
HttpServletMapping includeMapping = (HttpServletMapping)getAttribute(INCLUDE_MAPPING);
if (_named == null) if (_named == null)
{ {
if (pathInfo != null)
set.add(INCLUDE_PATH_INFO); set.add(INCLUDE_PATH_INFO);
if (_requestURI != null)
set.add(INCLUDE_REQUEST_URI); set.add(INCLUDE_REQUEST_URI);
if (servletPath != null)
set.add(INCLUDE_SERVLET_PATH); set.add(INCLUDE_SERVLET_PATH);
if (contextPath != null)
set.add(INCLUDE_CONTEXT_PATH); set.add(INCLUDE_CONTEXT_PATH);
if (includeMapping != null)
set.add(INCLUDE_MAPPING); set.add(INCLUDE_MAPPING);
if (_query != null)
set.add(INCLUDE_QUERY_STRING); set.add(INCLUDE_QUERY_STRING);
} }