Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #4985 - fix NPE related to use of Attributes.Wrapper getAttributeNameSet() Jetty 10 #5046

Merged
merged 3 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ 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 +55,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 +71,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
54 changes: 38 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 @@ -26,6 +26,7 @@
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

Expand Down Expand Up @@ -244,7 +245,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 +255,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 +270,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 +306,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 +436,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);
HttpServletMapping includeMapping = (HttpServletMapping)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