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

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

spring-issuemaster opened this issue Jan 2, 2019 · 0 comments


Copy link

@spring-issuemaster spring-issuemaster commented Jan 2, 2019

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:

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:

Issue Links:

  • #21783 Improve WebFlux performance for header management

Referenced from: commits 6e3f974

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