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

NPE when passing null value to Request.param #12018

Closed
mperktold opened this issue Jul 9, 2024 · 1 comment · Fixed by #12024
Closed

NPE when passing null value to Request.param #12018

mperktold opened this issue Jul 9, 2024 · 1 comment · Fixed by #12024
Labels
Bug For general bugs on Jetty side

Comments

@mperktold
Copy link

Jetty version(s)
Jetty 12.0.10

Jetty Environment
core

Java version/vendor (use: java -version)
openjdk version "21.0.3" 2024-04-16 LTS
OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode, sharing)

OS type/version
Windows 11

Description
When passing null as a query parameter value to Request.param, a NullPointerException is thrown. It happens when the value is wrapped in a List using List.of, which doesn't like null values.

I don't think this is intentional. With Jetty 11, null values were allowed. Also, the value is passed to a private method urlEncode, which allows null and is only used for query parameters:

How to reproduce?

var httpClient = new HttpClient();
httpClient.start();
System.out.println(
    httpClient.newRequest("https://google.com/search")
        .param("q", null)
        .send()
);
httpClient.stop();

When running the above code with Jetty 12, it throws the following exception:

Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.Objects.requireNonNull(Objects.java:233)
	at java.base/java.util.ImmutableCollections$List12.<init>(ImmutableCollections.java:563)
	at java.base/java.util.List.of(List.java:937)
	at org.eclipse.jetty.util.Fields$Field.<init>(Fields.java:366)
	at org.eclipse.jetty.util.Fields.lambda$add$0(Fields.java:225)
	at java.base/java.util.HashMap.compute(HashMap.java:1324)
	at org.eclipse.jetty.util.Fields.add(Fields.java:221)
	at org.eclipse.jetty.client.transport.HttpRequest.param(HttpRequest.java:334)
	at org.eclipse.jetty.client.transport.HttpRequest.param(HttpRequest.java:329)
	...

It works fine with Jetty 11 though.

@mperktold mperktold added the Bug For general bugs on Jetty side label Jul 9, 2024
lorban added a commit that referenced this issue Jul 10, 2024
@lorban
Copy link
Contributor

lorban commented Jul 10, 2024

This does look like a regression that we should fix.

Thanks for the report!

lorban added a commit that referenced this issue Jul 12, 2024
#12018 make Fields interpret null values as empty strings

Signed-off-by: Ludovic Orban <[email protected]>
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
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

2 participants