Skip to content

Commit

Permalink
Merge pull request #6655 from eclipse/jetty-10.0.x-6654-websocket-upg…
Browse files Browse the repository at this point in the history
…rade-npe-request-cookies

Issue #6654 - Fix NPEs from bad Servlet API use
  • Loading branch information
joakime committed Aug 25, 2021
2 parents 325739b + a82b45c commit 3badb86
Showing 1 changed file with 18 additions and 6 deletions.
Expand Up @@ -29,6 +29,7 @@
import java.util.TreeMap;
import java.util.stream.Collectors;
import javax.servlet.ServletRequest;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

Expand Down Expand Up @@ -90,9 +91,17 @@ public List<HttpCookie> getCookies()
{
if (cookies == null)
{
cookies = Arrays.stream(request.getCookies())
.map(c -> new HttpCookie(c.getName(), c.getValue()))
.collect(Collectors.toList());
Cookie[] reqCookies = request.getCookies();
if (reqCookies != null)
{
cookies = Arrays.stream(reqCookies)
.map(c -> new HttpCookie(c.getName(), c.getValue()))
.collect(Collectors.toList());
}
else
{
cookies = Collections.emptyList();
}
}

return cookies;
Expand Down Expand Up @@ -135,10 +144,13 @@ public Map<String, List<String>> getHeadersMap()
{
Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements())
if (headerNames != null)
{
String name = headerNames.nextElement();
headers.put(name, Collections.list(request.getHeaders(name)));
while (headerNames.hasMoreElements())
{
String name = headerNames.nextElement();
headers.put(name, Collections.list(request.getHeaders(name)));
}
}
return headers;
}
Expand Down

0 comments on commit 3badb86

Please sign in to comment.