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

IllegalArgumentException: HttpEntity parameter 'null' [SPR-14799] #19365

Closed
spring-projects-issues opened this issue Oct 11, 2016 · 4 comments
Closed
Assignees
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Oct 11, 2016

David Zhu opened SPR-14799 and commented

This is probably related to #16892.

We are returning a DeferredResult<?>, with ? always being ResponseEntity<?>

If we change the signature to DeferredResult<ResponseEntity<?>> the error does not occur.


Affects: 4.3.2

Issue Links:

  • #16892 HttpEntity parameter 'null' in method (regression)
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 11, 2016

Rossen Stoyanchev commented

I tried the following and can't make it happen.

  @GetMapping("/foo")
  public DeferredResult<?> foo() {
    final DeferredResult<Object> result = new DeferredResult<Object>();

    new Thread(new Runnable() {

      @Override
      public void run() {
        try {
          Thread.sleep(3000);
        }
        catch (InterruptedException ex) {
          ex.printStackTrace();
        }
        result.setResult(ResponseEntity.ok("foo"));
      }
    }).start();

    return result;
  }
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 12, 2016

David Zhu commented

Hello Rossen,

Thanks for taking a look at this.

Try

DeferredResult<?> r = new DeferredResult<?>();
r.setResult(new ResponseEntity(HttpStatus.NOT_MODIFIED));
return r;
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 12, 2016

Rossen Stoyanchev commented

Okay that does it.

So in the regular ResponseEntity<?> return value type case we can check the return value or at least find the wildcard from the generic type if there is no body. However with DeferredResult<?> and with no body the generic type checks reach a situation that is not expected and raise an IllegalStateException:

java.lang.IllegalArgumentException: HttpEntity parameter &apos;null&apos; in method public org.springframework.web.context.request.async.DeferredResult org.springframework.issues.config.TestController.foo() is not parameterized
	at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.getHttpEntityType(HttpEntityMethodProcessor.java:150)
	at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.getReturnValueType(HttpEntityMethodProcessor.java:279)
	at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:179)
	at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:198)

I suppose we can relax this to return Object.class and let the message conversion process work itself out from there. After all at this point we do know that it is a ResponseEntity but we just can't figure out the body type. And in this case there is not even a body.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 13, 2016

Rossen Stoyanchev commented

A fix is now available in 4.3.x and master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants