From 9b951c0cd29f6c634c43401746d8bb154dec925e Mon Sep 17 00:00:00 2001 From: Heewon Lee <94441510+pingpingy1@users.noreply.github.com> Date: Wed, 24 Jan 2024 17:57:58 +0900 Subject: [PATCH] Fixed NullPointerException Bug (#2304) `RequestTemplate.header(name, values)` method has two overloaded implementations. In the case where `values` has type `Iterable`, `values` is guarded against `null`. This does not happen when `values` has type `String...`, which is fixed by this commit. --- core/src/main/java/feign/RequestTemplate.java | 6 +++++- core/src/test/java/feign/RequestTemplateTest.java | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/feign/RequestTemplate.java b/core/src/main/java/feign/RequestTemplate.java index 22e176db1..09124a855 100644 --- a/core/src/main/java/feign/RequestTemplate.java +++ b/core/src/main/java/feign/RequestTemplate.java @@ -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 @@ -704,6 +704,10 @@ public Map> 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)); } diff --git a/core/src/test/java/feign/RequestTemplateTest.java b/core/src/test/java/feign/RequestTemplateTest.java index 422281e94..6c1d66931 100644 --- a/core/src/test/java/feign/RequestTemplateTest.java +++ b/core/src/test/java/feign/RequestTemplateTest.java @@ -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 @@ -558,4 +558,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); + } }