Skip to content

Client.Default - Null pointer exception when receiving an 'empty' response with compression #2509

@TiagoCamilo

Description

@TiagoCamilo

Hello! Could you please evaluate the situation below and determine if it's necessary to implement an improvement?

When using Client.Default, and the server responds with:

  • HTTP code: >= 400
  • Header: Content-Encoding: gzip (or deflate)
  • Body: "empty"

The following exception occurs:

java.lang.NullPointerException: null
	at java.base/java.util.zip.InflaterInputStream.<init>(InflaterInputStream.java:84) ~[na:na]
	at java.base/java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:77) ~[na:na]
	at java.base/java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:91) ~[na:na]
	at feign.Client$Default.convertResponse(Client.java:138) ~[feign-core-13.3.jar:na]
	at feign.Client$Default.execute(Client.java:107) ~[feign-core-13.3.jar:na]
	at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:100) ~[feign-core-13.3.jar:na]
	at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:70) ~[feign-core-13.3.jar:na]
	at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:99) ~[feign-core-13.3.jar:na]
	at com.example.feign_example.$Proxy63.test(Unknown Source) ~[na:na]

Below is an example of an endpoint that reproduces this response:

@PostMapping("/empty-body")
public ResponseEntity<byte[]> emptyBody() {
    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.CONTENT_ENCODING, "gzip");

    return ResponseEntity.status(HttpStatus.BAD_REQUEST).headers(headers).build();
}

In my opinion, the ideal result would be for a FeignException to occur with the HTTP code returned by the server, just as it does when the response body is not empty.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions