Skip to content

Commit

Permalink
Issue #6654 - Fix NPEs from bad Servlet API use
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Aug 23, 2021
1 parent b2c420a commit 401f195
Showing 1 changed file with 14 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,13 @@ 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());
}
}

return cookies;
Expand Down Expand Up @@ -135,10 +140,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 401f195

Please sign in to comment.