Fix setAll method transformation in HttpHeadersCustomRecipe to properly convert Map to HttpHeaders
The HttpHeadersCustomRecipe contained a logic bug in the setAll method migration that incorrectly assumed type compatibility between java.util.Map and io.clientcore.core.http.models.HttpHeaders.
Problem
The original transformation was:
// Before (azure-core)
headers.setAll(someMap); // Map<String, List<String>>
// After (buggy clientcore transformation)
headers.setAll(someMap); // Treated someMap as HttpHeaders - incorrect!
This failed because:
- Azure-core
HttpHeaders.setAll()acceptedMap<String, List<String>> - Clientcore
HttpHeaders.setAll()only acceptsHttpHeadersobjects - The template assumed direct type compatibility without conversion
Solution
Now properly converts the Map to HttpHeaders using stream-based collection:
// Before (azure-core)
headers.setAll(headerMap);
// After (fixed clientcore transformation)
headers.setAll(headerMap.entrySet().stream().collect(
HttpHeaders::new,
(newHeaders, entry) -> newHeaders.set(
HttpHeaderName.fromString(entry.getKey()),
entry.getValue() instanceof java.util.List ?
(java.util.List<String>) entry.getValue() :
java.util.Collections.singletonList(entry.getValue().toString())
),
HttpHeaders::setAll
));
Key Features
- ✅ Creates new
HttpHeadersinstance from the inputMap - ✅ Handles both
StringandList<String>values properly - ✅ Uses
HttpHeaderName.fromString()for proper key conversion - ✅ No variable assignments in template (customer code agnostic)
- ✅ Adds all necessary imports (
HttpHeaders,HttpHeaderName,Collections)
Testing
Added comprehensive test case demonstrating the transformation with realistic Map usage including multiple header types.
Fixes #45608.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.
@copilot The source code minimum is java 8. We cannot use text blocks. Alter the implementation to be Java 8 compatible.
@copilot The source code minimum is java 8. We cannot use text blocks. Alter the implementation to be Java 8 compatible.
Fixed in commit 3ab7350. Converted text blocks to Java 8 compatible string concatenation using + operator and explicit newline characters.
API Change Check
APIView identified API level changes in this PR and created the following API reviews
Hi @Copilot. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days.
Hi @Copilot. Thank you for your interest in helping to improve the Azure SDK experience and for your contribution. We've noticed that there hasn't been recent engagement on this pull request. If this is still an active work stream, please let us know by pushing some changes or leaving a comment. Otherwise, we'll close this out in 7 days.