@Test
  void doNotCloseAfterDecodeDecoderFailure() {
    server.enqueue(new MockResponse().setBody("success!"));

    String url = "http://localhost:" + server.getPort();
    Decoder angryDecoder =
        (response, type) -> {
          throw new IOException("Failed to decode the response");
        };

    final AtomicBoolean closed = new AtomicBoolean();
    TestInterface api =
        Feign.builder()
            .client(
                new Client() {
                  Client client = new Client.Default(null, null);

                  @Override
                  public Response execute(Request request, Request.Options options)
                      throws IOException {
                    final Response original = client.execute(request, options);
                    return Response.builder()
                        .status(original.status())
                        .headers(original.headers())
                        .reason(original.reason())
                        .request(original.request())
                        .body(
                            new Response.Body() {
                              @Override
                              public Integer length() {
                                return original.body().length();
                              }

                              @Override
                              public boolean isRepeatable() {
                                return original.body().isRepeatable();
                              }

                              @Override
                              public InputStream asInputStream() throws IOException {
                                return original.body().asInputStream();
                              }

                              @SuppressWarnings("deprecation")
                              @Override
                              public Reader asReader() throws IOException {
                                return original.body().asReader(Util.UTF_8);
                              }

                              @Override
                              public Reader asReader(Charset charset) throws IOException {
                                return original.body().asReader(charset);
                              }

                              @Override
                              public void close() throws IOException {
                                closed.set(true);
                                original.body().close();
                              }
                            })
                        .build();
                  }
                })
            .decoder(angryDecoder)
            .doNotCloseAfterDecode()
            .target(TestInterface.class, url);
    try {
      api.decodedLazyPost();
      fail("Expected an exception");
    } catch (FeignException expected) {
    }
    assertThat(closed.get()).as("Responses must be closed when the decoder fails").isTrue();
  }
When {@link Feign.Builder#doNotCloseAfterDecode()} is enabled an an exception is thrown from
the {@link Decoder}, the response should be closed.
core/src/test/java/feign/FeignBuilderTest.java