You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2023/12/19 19:16:55 UTC
(httpcomponents-core) 01/01: Fix: URIBuilder.getFirstQueryParam throws NPE when query is emty (#449)
This is an automated email from the ASF dual-hosted git repository.
olegk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/httpcomponents-core.git
commit 3b8b2e748145183467d1257abc182b9d94fe46cc
Author: Konstantin Sorokin <sk...@gmail.com>
AuthorDate: Tue Dec 19 22:07:20 2023 +0300
Fix: URIBuilder.getFirstQueryParam throws NPE when query is emty (#449)
---
httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java | 3 +++
httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java | 2 ++
2 files changed, 5 insertions(+)
diff --git a/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java b/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java
index 5f3c0fac9..b6f7a6df6 100644
--- a/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java
+++ b/httpcore5/src/main/java/org/apache/hc/core5/net/URIBuilder.java
@@ -967,6 +967,9 @@ public class URIBuilder {
* @since 5.2
*/
public NameValuePair getFirstQueryParam(final String name) {
+ if (queryParams == null) {
+ return null;
+ }
return queryParams.stream().filter(e -> name.equals(e.getName())).findFirst().orElse(null);
}
diff --git a/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java b/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java
index 31a567198..3642855bb 100644
--- a/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java
+++ b/httpcore5/src/test/java/org/apache/hc/core5/net/TestURIBuilder.java
@@ -399,6 +399,8 @@ public class TestURIBuilder {
//
uribuilder = new URIBuilder("http://localhost:80/?param=some%20other%20stuff&blah=blah&blah=blah2");
Assertions.assertEquals("blah", uribuilder.getFirstQueryParam("blah").getValue());
+ uribuilder.removeQuery();
+ Assertions.assertNull(uribuilder.getFirstQueryParam("param"));
}
@Test