Skip to content

Commit 027a97d

Browse files
Document when EncodeException can have a null message (#3704)
* Document when EncodeException can have a null message * Assert the original encoder message and cause
1 parent a76f92b commit 027a97d

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

‎core/src/main/java/feign/codec/EncodeException.java‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,20 @@ public class EncodeException extends FeignException {
2929
private static final long serialVersionUID = 1L;
3030

3131
/**
32-
* @param message the reason for the failure.
32+
* Creates an encoding failure with a required detail message.
33+
*
34+
* @param message the non-null reason for the failure.
3335
*/
3436
public EncodeException(String message) {
3537
super(-1, checkNotNull(message, "message"));
3638
}
3739

3840
/**
39-
* @param message possibly null reason for the failure.
40-
* @param cause the cause of the error.
41+
* Creates an encoding failure with an underlying cause. Feign wraps exceptions from encoders
42+
* using their original detail messages, which may be {@code null}.
43+
*
44+
* @param message the reason for the failure, which may be {@code null}.
45+
* @param cause the non-null cause of the error.
4146
*/
4247
public EncodeException(String message, Throwable cause) {
4348
super(-1, message, checkNotNull(cause, "cause"));

‎core/src/test/java/feign/FeignTest.java‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,16 +961,20 @@ void decodingDoesNotSwallow404ErrorsInDismiss404Mode() throws Exception {
961961
@Test
962962
void okIfEncodeRootCauseHasNoMessage() throws Exception {
963963
server.enqueue(new MockResponse().setBody("success!"));
964+
RuntimeException cause = new RuntimeException();
964965

965966
TestInterface api =
966967
new TestInterfaceBuilder()
967968
.encoder(
968969
(_, _, _) -> {
969-
throw new RuntimeException();
970+
throw cause;
970971
})
971972
.target("http://localhost:" + server.getPort());
972973

973-
assertThrows(EncodeException.class, () -> api.body(Arrays.asList("foo")));
974+
EncodeException exception =
975+
assertThrows(EncodeException.class, () -> api.body(Arrays.asList("foo")));
976+
assertThat(exception.getMessage()).isNull();
977+
assertThat(exception.getCause()).isSameAs(cause);
974978
}
975979

976980
@Test

0 commit comments

Comments
 (0)