From 32eacdcca272ec623a5c2c9953a5140068c28265 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 a6836c50c..3daed51bb 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 @@ -703,6 +703,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 099748e7e..23588dc2a 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 @@ -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); + } }