Fix WirespecWebClient ClassCastException on Spring Framework 7 / Spring Boot 4#671
Merged
Merged
Conversation
WirespecWebClient converted downstream response headers by passing Spring's HttpHeaders straight into CollectionUtils.toMultiValueMap, which relies on HttpHeaders being a Map. In Spring Framework 6 HttpHeaders implements MultiValueMap (and therefore Map), but in Spring Framework 7 (Spring Boot 4) HttpHeaders no longer does, so a jar compiled against Spring 6 throws: ClassCastException: ReadOnlyHttpHeaders cannot be cast to java.util.Map at runtime on Spring 7 for every response. Convert headers by iterating via HttpHeaders.forEach(BiConsumer) into a LinkedMultiValueMap instead. That method exists with an identical binary descriptor on both Spring 6 (inherited from Map) and Spring 7 (declared directly), so a single jar compiled against Spring 6 keeps working on both versions. Applied to both the Kotlin and Java WirespecWebClient. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GFtN52uDWW7dgxwQE5kEGb
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GFtN52uDWW7dgxwQE5kEGb
wilmveel
approved these changes
Jun 19, 2026
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
WirespecWebClient(both the Kotlin and Java reactive clients) threw aClassCastExceptionon every response when running on Spring Framework 7 / Spring Boot 4:Root cause
The clients converted downstream response headers into the
Map<String, List<String>>expected byWirespec.RawResponseby passing Spring'sHttpHeadersstraight intoCollectionUtils.toMultiValueMap(...), which relies onHttpHeadersbeing aMap.HttpHeaders implements MultiValueMap<String, String>(and thereforeMap), so the upcast is valid and the artifact compiles cleanly.HttpHeaderswas redesigned and no longer implementsMap/MultiValueMap. The published jar — compiled against Spring 6 — therefore fails the cast at runtime on Spring 7.Fix
Stop assuming
HttpHeadersis aMap. Convert headers by iterating viaHttpHeaders.forEach(BiConsumer)into aLinkedMultiValueMap, replacing the threetoMultiValueMap(...)call sites in each client.Backwards compatibility ✅
The change is binary compatible with both Spring 6 and Spring 7.
forEach(BiConsumer<? super String, ? super List<String>>)exists with an identical binary descriptor(Ljava/util/function/BiConsumer;)Vin both versions:MapHttpHeadersSo a single jar compiled against Spring 6 (as this repo is, on
spring-webflux 6.1.13) resolves the call correctly at runtime on Spring 7 as well. NokeySet()/headerNames()(which differ between versions) is used.Changes
WirespecWebClient.kt(Kotlin) — added a privateHttpHeaders.toRawHeaders()helper and replaced all threetoMultiValueMap(...)call sites.WirespecWebClient.java(Java) — added a privatestatic toRawHeaders(HttpHeaders)helper and replaced all threeCollectionUtils.toMultiValueMap(...)call sites.Verification
:src:integration:spring:compileKotlinJvmandcompileJvmMainJavacompile cleanly against Spring 6.1.13.*it.client.*), includingResponseHeaderCaseInsensitivityTest, which exercise the exact response-header mapping path, pass.🤖 Generated with Claude Code
Generated by Claude Code