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

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


None yet
2 participants
Copy link

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).


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

// ...

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]}>

	at org.springframework.util.LinkedCaseInsensitiveMap.putAll(
	at org.springframework.http.HttpHeaders.putAll(
	at org.springframework.http.ResponseEntity$DefaultBuilder.headers(
	at org.springframework.http.ResponseEntity$DefaultBuilder.headers(
	at ResponseEntityTest.createResponseEntity(
	at ResponseEntityTest.test(

Affects: 4.1.5

Referenced from: pull request #753


This comment has been minimized.

Copy link
Collaborator Author

commented Mar 6, 2015

Kazuki Shimizu commented

I submitted a pull request.


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!


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.