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 #6654 - Fix NPEs from bad Servlet API use #6655

Merged

Conversation

joakime
Copy link
Contributor

@joakime joakime commented Aug 23, 2021

Signed-off-by: Joakim Erdfelt joakim.erdfelt@gmail.com

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
@joakime joakime self-assigned this Aug 23, 2021
@joakime joakime added the Bug For general bugs on Jetty side label Aug 23, 2021
@joakime joakime added this to In progress in Jetty 10.0.7/11.0.7 FROZEN via automation Aug 23, 2021
@@ -135,10 +140,13 @@ public int getHeaderInt(String name)
{
Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements())
if (headerNames != null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The servlet spec indicates that this can also be null.

@joakime joakime linked an issue Aug 23, 2021 that may be closed by this pull request
Jetty 10.0.7/11.0.7 FROZEN automation moved this from In progress to Review in progress Aug 23, 2021
Copy link
Contributor

@sbordet sbordet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like returning null if there are no cookies, as it is prone to errors 😃

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
@joakime joakime requested a review from sbordet August 23, 2021 21:02
sbordet
sbordet previously approved these changes Aug 23, 2021
Jetty 10.0.7/11.0.7 FROZEN automation moved this from Review in progress to Reviewer approved Aug 23, 2021
}
else
{
cookies = List.of();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we also return null here if the request had no cookies?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had this discussion already recently and determined that emptyList was both more readable and more effficient.

Suggested change
cookies = List.of();
cookies = Collections.emptyList();

gregw
gregw previously requested changes Aug 24, 2021
Copy link
Contributor

@gregw gregw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one tiny niggle....

}
else
{
cookies = List.of();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had this discussion already recently and determined that emptyList was both more readable and more effficient.

Suggested change
cookies = List.of();
cookies = Collections.emptyList();

Jetty 10.0.7/11.0.7 FROZEN automation moved this from Reviewer approved to Review in progress Aug 24, 2021
@joakime
Copy link
Contributor Author

joakime commented Aug 24, 2021

one tiny niggle....

The call to List.of() is actually a call to ImmutableCollections.emptyList() (jvm package private class) already, which seems more correct than Collections.emptyList().
All uses of List.of(...) result in immutable lists.

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
@joakime joakime dismissed gregw’s stale review August 25, 2021 15:57

Change has been applied

@sbordet sbordet self-requested a review August 25, 2021 16:00
Jetty 10.0.7/11.0.7 FROZEN automation moved this from Review in progress to Reviewer approved Aug 25, 2021
@joakime joakime merged commit 3badb86 into jetty-10.0.x Aug 25, 2021
Jetty 10.0.7/11.0.7 FROZEN automation moved this from Reviewer approved to Done Aug 25, 2021
@joakime joakime deleted the jetty-10.0.x-6654-websocket-upgrade-npe-request-cookies branch August 25, 2021 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

ServerUpgradeRequest.getCookies() can throws NullPointerException
4 participants