Skip to content

Commit

Permalink
Issue #4985 - fix NPE related to use of Attributes.Wrapper getAttribu…
Browse files Browse the repository at this point in the history
…teNameSet()

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Jul 13, 2020
1 parent 3ddccfe commit 6325d4b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@ class AsyncAttributes extends Attributes.Wrapper
{
private final String _requestURI;
private final String _contextPath;
private final String _pathInContext;
private ServletPathMapping _mapping;
private final ServletPathMapping _mapping;
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)
{
super(attributes);
_requestURI = requestUri;
_contextPath = contextPath;
_pathInContext = pathInContext;
_servletPath = mapping == null ? null : mapping.getServletPath();
_pathInfo = mapping == null ? pathInContext : mapping.getPathInfo();
_mapping = mapping;
_queryString = queryString;
}
Expand All @@ -52,9 +56,9 @@ public Object getAttribute(String key)
case AsyncContext.ASYNC_CONTEXT_PATH:
return _contextPath;
case AsyncContext.ASYNC_SERVLET_PATH:
return _mapping == null ? null : _mapping.getServletPath();
return _servletPath;
case AsyncContext.ASYNC_PATH_INFO:
return _mapping == null ? _pathInContext : _mapping.getPathInfo();
return _pathInfo;
case AsyncContext.ASYNC_QUERY_STRING:
return _queryString;
case AsyncContext.ASYNC_MAPPING:
Expand All @@ -68,12 +72,18 @@ public Object getAttribute(String key)
public Set<String> getAttributeNameSet()
{
Set<String> set = new HashSet<>(super.getAttributeNameSet());
set.add(AsyncContext.ASYNC_REQUEST_URI);
set.add(AsyncContext.ASYNC_CONTEXT_PATH);
set.add(AsyncContext.ASYNC_SERVLET_PATH);
set.add(AsyncContext.ASYNC_PATH_INFO);
set.add(AsyncContext.ASYNC_QUERY_STRING);
set.add(AsyncContext.ASYNC_MAPPING);
if (_requestURI != null)
set.add(AsyncContext.ASYNC_REQUEST_URI);
if (_contextPath != null)
set.add(AsyncContext.ASYNC_CONTEXT_PATH);
if (_servletPath != null)
set.add(AsyncContext.ASYNC_SERVLET_PATH);
if (_pathInfo != null)
set.add(AsyncContext.ASYNC_PATH_INFO);
if (_queryString != null)
set.add(AsyncContext.ASYNC_QUERY_STRING);
if (_mapping != null)
set.add(AsyncContext.ASYNC_MAPPING);
return set;
}

Expand Down
53 changes: 37 additions & 16 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Dispatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ private class ForwardAttributes extends Attributes.Wrapper
{
private final String _requestURI;
private final String _contextPath;
private final String _pathInContext;
private final String _servletPath;
private final String _pathInfo;
private final ServletPathMapping _servletPathMapping;
private final String _query;

Expand All @@ -253,9 +254,11 @@ public ForwardAttributes(Attributes attributes, String requestURI, String contex
super(attributes);
_requestURI = requestURI;
_contextPath = contextPath;
_pathInContext = pathInContext;
_servletPathMapping = mapping;
_query = query;

_pathInfo = _servletPathMapping == null ? pathInContext : _servletPathMapping.getPathInfo();
_servletPath = _servletPathMapping == null ? null : _servletPathMapping.getServletPath();
}

@Override
Expand All @@ -266,11 +269,11 @@ public Object getAttribute(String key)
switch (key)
{
case FORWARD_PATH_INFO:
return _servletPathMapping == null ? _pathInContext : _servletPathMapping.getPathInfo();
return _pathInfo;
case FORWARD_REQUEST_URI:
return _requestURI;
case FORWARD_SERVLET_PATH:
return _servletPathMapping == null ? null : _servletPathMapping.getServletPath();
return _servletPath;
case FORWARD_CONTEXT_PATH:
return _contextPath;
case FORWARD_QUERY_STRING:
Expand Down Expand Up @@ -302,12 +305,18 @@ public Set<String> getAttributeNameSet()

if (_named == null)
{
set.add(FORWARD_PATH_INFO);
set.add(FORWARD_REQUEST_URI);
set.add(FORWARD_SERVLET_PATH);
set.add(FORWARD_CONTEXT_PATH);
set.add(FORWARD_MAPPING);
set.add(FORWARD_QUERY_STRING);
if (_pathInfo != null)
set.add(FORWARD_PATH_INFO);
if (_requestURI != null)
set.add(FORWARD_REQUEST_URI);
if (_servletPath != null)
set.add(FORWARD_SERVLET_PATH);
if (_contextPath != null)
set.add(FORWARD_CONTEXT_PATH);
if (_servletPathMapping != null)
set.add(FORWARD_MAPPING);
if (_query != null)
set.add(FORWARD_QUERY_STRING);
}

return set;
Expand Down Expand Up @@ -426,14 +435,26 @@ public Set<String> getAttributeNameSet()
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);
String includeMapping = (String)getAttribute(INCLUDE_MAPPING);

if (_named == null)
{
set.add(INCLUDE_PATH_INFO);
set.add(INCLUDE_REQUEST_URI);
set.add(INCLUDE_SERVLET_PATH);
set.add(INCLUDE_CONTEXT_PATH);
set.add(INCLUDE_MAPPING);
set.add(INCLUDE_QUERY_STRING);
if (pathInfo != null)
set.add(INCLUDE_PATH_INFO);
if (_requestURI != null)
set.add(INCLUDE_REQUEST_URI);
if (servletPath != null)
set.add(INCLUDE_SERVLET_PATH);
if (contextPath != null)
set.add(INCLUDE_CONTEXT_PATH);
if (includeMapping != null)
set.add(INCLUDE_MAPPING);
if (_query != null)
set.add(INCLUDE_QUERY_STRING);
}

return set;
Expand Down

0 comments on commit 6325d4b

Please sign in to comment.