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

RestClient ResponseSpec.body() when using Reactor Netty throws an exception instead of returning null if no response body is available #32934

Closed
r16turbo opened this issue Jun 1, 2024 · 1 comment
Labels
status: duplicate A duplicate of another issue

Comments

@r16turbo
Copy link

r16turbo commented Jun 1, 2024

I will post again as it seems to be caused by RestClient.

Environment: Spring Web 6.1.8, Java 17

The situation is the same as in #31719, which occurs when using Reactor Netty.

Test code:
https://github.com/r16turbo/restclient-test/blob/main/src/test/java/com/example/demo/DemoApplicationTests.java
👆 Fails in the last test case (reactorNettyTest).

The reason is that the following code throws an exception:

https://github.com/spring-projects/spring-framework/blob/v6.1.8/spring-web/src/main/java/org/springframework/http/client/ReactorNettyClientResponse.java#L85

I believe that null should also be returned when using Reactor Netty, please let me know about a better way to implement this.

Example of a simple fix:
(However, Java 11 or higher is required)

	@Override
	public InputStream getBody() throws IOException {
		InputStream body = this.body;
		if (body != null) {
			return body;
		}

		body = this.connection.inbound().receive()
				.aggregate().asInputStream().block(this.readTimeout);
		if (body == null) {
			// throw new IOException("Could not receive body");
			body = InputStream.nullInputStream();  // 👈 here
		}
		this.body = body;
		return body;
	}

Thanks

@bclozel
Copy link
Member

bclozel commented Jun 1, 2024

duplicates #32805

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Jun 1, 2024
@bclozel bclozel added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants