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

Fixed NullPointerException Bug #2304

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}