In 5.1 HttpHeaders became a MultiValueMap and it became possible to wrap existing HttpHeaders instances rather than copy their contents. As a result it's possible to have multiple HttpHeaders wrappers around the actual MultiValueMap content.

The equals method tries to compare the MultiValueMap content by nesting on the headers field but if the levels of nesting are uneven, it may return false. For example:

HttpHeaders headers1 = new HttpHeaders();
HttpHeaders headers2 = new HttpHeaders(new HttpHeaders(headers1));

assertThat(headers1.equals(headers2)).isTrue(); // Pass
assertThat(headers2.equals(headers1)).isTrue(); // Fail

Comment From: jhoeller

Let's backport this to 5.1.x as well then, given that it dates back to a 5.1 change... and that the equals implementation seems to be the same.

Comment From: snicoll

This is a binary incompatible change that breaks Spring REST docs, can we please reconsider it?

Tests run: 4, Failures: 0, Errors: 4, Skipped: 0, Time elapsed: 0.435 s <<< FAILURE! - in org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation.CachesEndpointDocumentationTests
evictAllCaches(org.springframework.boot.actuate.autoconfigure.endpoint.web.documentation.CachesEndpointDocumentationTests)  Time elapsed: 0.012 s  <<< ERROR!
java.lang.NoSuchMethodError: org.springframework.http.HttpHeaders.readOnlyHttpHeaders(Lorg/springframework/http/HttpHeaders;)Lorg/springframework/http/HttpHeaders;
    at org.springframework.restdocs.operation.HttpHeadersHelper.getHeaders(HttpHeadersHelper.java:63)
    at org.springframework.restdocs.operation.OperationRequestFactory.augmentHeaders(OperationRequestFactory.java:109)
    at org.springframework.restdocs.operation.OperationRequestFactory.create(OperationRequestFactory.java:48)
    at org.springframework.restdocs.mockmvc.MockMvcRequestConverter.convert(MockMvcRequestConverter.java:76)
    at org.springframework.restdocs.mockmvc.MockMvcRequestConverter.convert(MockMvcRequestConverter.java:55)
    at org.springframework.restdocs.generate.RestDocumentationGenerator.handle(RestDocumentationGenerator.java:186)

Comment From: jhoeller

It seems that the accepted argument got relaxed from HttpHeaders to MultiValueMap<String, String> which is source compatible but not binary compatible. The relaxed variant only seems to be used in master, so I suppose we'll keep it as an overloaded variant there, even if we still have to reintroduce the old signature there as well.

We need to change the signature back to the original in 5.2.x and 5.1.x. I've got a few other things to backport as well, so I'll take care of it.