Skip to content

Commit

Permalink
Fixed NullPointerException Bug (#2304)
Browse files Browse the repository at this point in the history
`RequestTemplate.header(name, values)` method has two overloaded implementations.
In the case where `values` has type `Iterable<String>`, `values` is guarded against `null`.
This does not happen when `values` has type `String...`, which is fixed by this commit.
  • Loading branch information
pingpingy1 authored Jan 24, 2024
1 parent 903a5d7 commit 32eacdc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 5 additions & 1 deletion core/src/main/java/feign/RequestTemplate.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 The Feign Authors
* Copyright 2012-2024 The Feign Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -703,6 +703,10 @@ public Map<String, Collection<String>> queries() {
* @see RequestTemplate#header(String, Iterable)
*/
public RequestTemplate header(String name, String... values) {
if (values == null) {
return appendHeader(name, Collections.emptyList());
}

return header(name, Arrays.asList(values));
}

Expand Down
10 changes: 9 additions & 1 deletion core/src/test/java/feign/RequestTemplateTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 The Feign Authors
* Copyright 2012-2024 The Feign Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -497,4 +497,12 @@ void encodedReservedEncodeSlash() {
template = template.resolve(Collections.singletonMap("url", "https://www.google.com"));
assertThat(template.url()).isEqualToIgnoringCase("/get?url=https%3A%2F%2Fwww.google.com");
}

@Test
void nullValuesOfHeaderShouldBeHandled() {
RequestTemplate template = new RequestTemplate();
String[] values = null;
String name = "";
template.header(name, values);
}
}

0 comments on commit 32eacdc

Please sign in to comment.