Skip to content

HttpHeaders.EMPTY is not immutable [SPR-17633] #22164

Closed

Description

@spring-projects-issues

Alfred Thomas opened SPR-17633 and commented

According to the Javadoc, HttpHeaders.EMPTY is immutable.
I found that by using the following code, headers could be added to HttpHeaders.EMPTY.
From then on, any further calls will result in a non-empty HttpHeaders.

HttpHeaders myHeaders = HttpHeaders.writableHttpHeaders(HttpHeaders.EMPTY);
my.add(HttpHeaders.ACCEPT_ENCODING, "gzip");

I have written a simple unit test to explain this issue:

@Test
public void testUpdateEmptyHeaders() {
    assertEquals(0, HttpHeaders.EMPTY.size()); // **Success**
    HttpHeaders myHeaders = HttpHeaders.writableHttpHeaders(HttpHeaders.EMPTY);
    myHeaders.add(HttpHeaders.ACCEPT_ENCODING, "gzip");
    assertEquals(0, HttpHeaders.EMPTY.size()); // **Assert Fails**
}

This caused a bug in my code where I subsequently used HttpHeaders.EMPTY again to create a new writable HttpHeaders object. I then unknowingly introduced headers used in the previous object


Affects: 5.1.3

Reference URL: https://stackoverflow.com/questions/53982635/possible-bug-in-spring-httpheaders

Issue Links:

Referenced from: commits 6e3f974

Activity

  1. added
    type: bug
    in: web
    on Jan 11, 2019
  2. added this to the 5.1.4 milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webtype: bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions