Azure / Azure/azure-sdk-for-java
Fix the bug identified in the setAll api migration of the HttpHeadersCustomRecipe
- Dominant language
- Java
- Stars
- 2.6k
- Forks
- 2.2k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 199
Description
This task is a prompt for GitHub Copilot to complete. Use a model that thinks deeply about the task at hand.
Before completing the following task, ingest the following documentation on how you should behave when completing this task: https://[raw.githubusercontent.com/Azure/azure-sdk-for-java/refs/heads/main/.github/copilot-instructions.md](https://raw.githubusercontent.com/Azure/azure-sdk-for-java/refs/heads/main/.github/copilot-instructions.md)
Here's the task: The recipe HttpHeadersCustomRecipe (located at sdk\tools\azure-openrewrite\src\main\java\com\azure\openrewrite\core\http\HttpHeadersCustomRecipe.java) contains a logic bug. This bug occurs for the `MethodMatcher` with the method pattern "com.azure.core.http.HttpHeaders setAll(java.util.Map)". Here's the affected code portion:
```java
methodMatcher = new MethodMatcher("com.azure.core.http.HttpHeaders setAll(java.util.Map)");
if (methodMatcher.matches(visitedMethodInvocation, true)) {
replacementTemplate = templateBuilder.getJavaTemplateBuilder("setAll(#{any(io.clientcore.core.http.models.HttpHeaders)})")
.imports("io.clientcore.core.http.models.HttpHeaders")
.build();
visitedMethodInvocation = replacementTemplate.apply(updateCursor(visitedMethodInvocation), visitedMethodInvocation.getCoordinates().replaceMethod(), visitedMethodInvocation.getArguments().toArray());
maybeAddImport("io.clientcore.core.http.models.HttpHeaders");
}
```
The input for getJavaTemplateBuilder needs to actually create an instance of io.clientcore.http.models.HttpHeaders from the type java.util.Map, not just assume the type change. This means that you need to crreate a new instance of HttpHeaders and iterate over all mappings in the map, assigning them as headers within the new HttpHeaders object. Do all of this without using any variable assignments in the java template, since you cannot assume the variable names being used by a customer.
Contributor guide
Assessment
This issue has not been assessed yet.