From 16f13f8a6c280904a4c08b4fce51c013ef7818b0 Mon Sep 17 00:00:00 2001 From: pingpingy1 Date: Wed, 24 Jan 2024 16:03:01 +0900 Subject: [PATCH] Fixed NullPointerException Bug `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 | 7 +++++ .../feign/jackson/jr/JacksonCodecTest.java | 26 +++++++++---------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/feign/RequestTemplate.java b/core/src/main/java/feign/RequestTemplate.java index a6836c50c1..e1dce72042 100644 --- a/core/src/main/java/feign/RequestTemplate.java +++ b/core/src/main/java/feign/RequestTemplate.java @@ -703,6 +703,13 @@ public Map> queries() { * @see RequestTemplate#header(String, Iterable) */ public RequestTemplate header(String name, String... values) { +<<<<<<< Updated upstream +======= + if (values == null) { + return appendHeader(name, Collections.emptyList()); + } + +>>>>>>> Stashed changes return header(name, Arrays.asList(values)); } diff --git a/jackson-jr/src/test/java/feign/jackson/jr/JacksonCodecTest.java b/jackson-jr/src/test/java/feign/jackson/jr/JacksonCodecTest.java index 937caa43ce..d09402820c 100644 --- a/jackson-jr/src/test/java/feign/jackson/jr/JacksonCodecTest.java +++ b/jackson-jr/src/test/java/feign/jackson/jr/JacksonCodecTest.java @@ -30,7 +30,6 @@ import java.util.Map; import java.util.Objects; import java.util.stream.Stream; - import org.junit.jupiter.api.Test; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.jr.ob.JSON; @@ -297,15 +296,16 @@ void notFoundDecodesToEmpty() throws Exception { @ParameterizedTest @MethodSource("decodeGenericsArguments") - void decodeGenerics(Response response, Type responseType, DataWrapper expectedDataWrapper) throws IOException { - assertThat(new JacksonJrDecoder().decode(response, responseType)).isEqualTo(expectedDataWrapper); + void decodeGenerics(Response response, Type responseType, DataWrapper expectedDataWrapper) + throws IOException { + assertThat(new JacksonJrDecoder().decode(response, responseType)) + .isEqualTo(expectedDataWrapper); } static class DataWrapper { private T data; - DataWrapper() { - } + DataWrapper() {} DataWrapper(T data) { this.data = data; @@ -317,8 +317,10 @@ public void setData(T data) { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; DataWrapper that = (DataWrapper) o; return Objects.equals(data, that.data); } @@ -332,19 +334,15 @@ static Stream decodeGenericsArguments() { "/v1/dummy", Collections.emptyMap(), Request.Body.empty(), - null - )); + null)); return Stream.of( Arguments.of( responseBuilder.body("{\"data\":2024}", StandardCharsets.UTF_8).build(), new TypeReference>() {}.getType(), - new DataWrapper<>(2024) - ), + new DataWrapper<>(2024)), Arguments.of( responseBuilder.body("{\"data\":\"Hello, World!\"}", StandardCharsets.UTF_8).build(), new TypeReference>() {}.getType(), - new DataWrapper<>("Hello, World!") - ) - ); + new DataWrapper<>("Hello, World!"))); } }