Skip to content

Commit

Permalink
Fixed NullPointerException Bug
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 committed Jan 24, 2024
1 parent 903a5d7 commit 16f13f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
7 changes: 7 additions & 0 deletions core/src/main/java/feign/RequestTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,13 @@ public Map<String, Collection<String>> 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));
}

Expand Down
26 changes: 12 additions & 14 deletions jackson-jr/src/test/java/feign/jackson/jr/JacksonCodecTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<T> {
private T data;

DataWrapper() {
}
DataWrapper() {}

DataWrapper(T data) {
this.data = data;
Expand All @@ -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);
}
Expand All @@ -332,19 +334,15 @@ static Stream<Arguments> 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<DataWrapper<Integer>>() {}.getType(),
new DataWrapper<>(2024)
),
new DataWrapper<>(2024)),
Arguments.of(
responseBuilder.body("{\"data\":\"Hello, World!\"}", StandardCharsets.UTF_8).build(),
new TypeReference<DataWrapper<String>>() {}.getType(),
new DataWrapper<>("Hello, World!")
)
);
new DataWrapper<>("Hello, World!")));
}
}

0 comments on commit 16f13f8

Please sign in to comment.