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

Jetty 12 IllegalArgumentExeption when setting a HTTP header to null #10508

Closed
ekupcik opened this issue Sep 13, 2023 · 5 comments · Fixed by #10510
Closed

Jetty 12 IllegalArgumentExeption when setting a HTTP header to null #10508

ekupcik opened this issue Sep 13, 2023 · 5 comments · Fixed by #10510
Labels
Bug For general bugs on Jetty side Specification For all industry Specifications (IETF / Servlet / etc)

Comments

@ekupcik
Copy link

ekupcik commented Sep 13, 2023

Jetty version(s)
12.0.1

Description
In jetty 12.0.1 calling HttpServletResponse.addHeader("name", null) throws an IllegalArgumentException

java.lang.IllegalArgumentException: null value
at org.eclipse.jetty.http.HttpFields$Mutable.add(HttpFields.java:901) ~[?:?]
at org.eclipse.jetty.ee10.servlet.ServletApiResponse.addHeader(ServletApiResponse.java:217) ~[?:?]

This used to work till 12.0.0 in Jetty, works in Tomcat and i also found this description jakartaee/servlet#159 This seems to be a regression

@ekupcik ekupcik added the Bug For general bugs on Jetty side label Sep 13, 2023
@ekupcik ekupcik changed the title IllegalArgumentExeption when setting a HTTP header to null Jetty 12 IllegalArgumentExeption when setting a HTTP header to null Sep 13, 2023
@joakime joakime added the Specification For all industry Specifications (IETF / Servlet / etc) label Sep 13, 2023
@joakime
Copy link
Contributor

joakime commented Sep 13, 2023

When you use HttpServletResponse.addHeader(name, value) you are adding a value to a list of values for a header.

Using HttpServletResponse.addHeader("X-Foo", null) would attempt to add a null value to the list of values to the header X-Foo.
That's invalid, hence the IllegalArgumentException

Note: If you had used HttpServletResponse.setHeader("X-Foo", null) then you are essentially removing that header (you are setting the header to have no value or values, which eliminates it)

@joakime
Copy link
Contributor

joakime commented Sep 13, 2023

The linked spec issue jakartaee/servlet#159 is about setHeader() not addHeader() btw.

@joakime
Copy link
Contributor

joakime commented Sep 13, 2023

The javadoc for the various setHeader / addHeader (and variants) calls out behavior when nulls are passed as parameters.

PR incoming.

@joakime
Copy link
Contributor

joakime commented Sep 13, 2023

Opened PR #10510 to address this

@joakime joakime moved this to 🏗 In progress in Jetty 12.0.2 FROZEN Sep 13, 2023
@gregw gregw moved this from 🏗 In progress to 👀 In review in Jetty 12.0.2 FROZEN Sep 13, 2023
joakime added a commit that referenced this issue Sep 14, 2023
…etHeader calls (#10510)

* Refactor ResponseHeadersTest to modern standards
* Issue #10508 - honor Servlet spec behaviors for null in addHeader / setHeader calls
@janbartel
Copy link
Contributor

Fixed via #10510

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 Specification For all industry Specifications (IETF / Servlet / etc)
Projects
None yet
3 participants