Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
TiagoCamilo opened this issue Aug 13, 2024 · 0 comments · Fixed by #2510

Comments

@TiagoCamilo
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant