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

Ignore null in HeadersBuilder#headers [SPR-12792] #17389

Closed
spring-issuemaster opened this issue Mar 6, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Mar 6, 2015

Kazuki Shimizu opened SPR-12792 and commented

If specified null value as method argument of HeadersBuilder#headers, NullPointerException occur.

I want to change this behavior as follows:

  • Ignore a null value(the same as HttpEntity constructor)
  • Check a null value using Assert#notNull method

I want to apply a first idea(ignore a null value).

e.g)

private ResponseEntity<String> createResponseEntity(
        String body,
        HttpHeaders customHeaders) {
    return ResponseEntity
            .ok()
            .headers(customHeaders)
            .header("X-Track", UUID.randomUUID().toString())
            .body(body);
}

// ...

@Test
public void test() {
    System.out.println(createResponseEntity("test", new HttpHeaders()));
    System.out.println(createResponseEntity("test", null));
}
<200 OK,test,{X-Track=[2a7ed446-c805-42a6-ada7-982ff9d2b6d7]}>

java.lang.NullPointerException
	at org.springframework.util.LinkedCaseInsensitiveMap.putAll(LinkedCaseInsensitiveMap.java:101)
	at org.springframework.http.HttpHeaders.putAll(HttpHeaders.java:907)
	at org.springframework.http.ResponseEntity$DefaultBuilder.headers(ResponseEntity.java:384)
	at org.springframework.http.ResponseEntity$DefaultBuilder.headers(ResponseEntity.java:364)
	at ResponseEntityTest.createResponseEntity(ResponseEntityTest.java:33)
	at ResponseEntityTest.test(ResponseEntityTest.java:17)
        ...

Affects: 4.1.5

Referenced from: pull request #753

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 6, 2015

Kazuki Shimizu commented

I submitted a pull request.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 10, 2015

Juergen Hoeller commented

Added with some minor polishing. Thanks for the contribution!

Juergen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.