Visitar URL original
Rename `getAllHeaders` where `HttpMessage` has already moved to its 5.x package by krlittle · Pull Request #176 · openrewrite/rewrite-apache · GitHub
Skip to content

Rename getAllHeaders where HttpMessage has already moved to its 5.x package - #176

Open
krlittle wants to merge 1 commit into
mainfrom
httpclient5-get-all-headers
Open

krlittle wants to merge 1 commit into
mainfrom
httpclient5-get-all-headers

Conversation

@krlittle

@krlittle krlittle commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

UpgradeApacheHttpClient_5_DeprecatedMethods renames getAllHeaders() to getHeaders() on org.apache.http.HttpMessage, but it runs after UpgradeApacheHttpClient_5_ClassMapping. In a file that uses types of the org.apache.http package itself (HttpResponse, Header, …), the org.apache.http → org.apache.hc.core5.http package change has by then also moved the method's declaring type, so the pattern no longer matches and the call keeps a name HttpClient 5 does not have:

// before
HttpResponse httpResponse = ...;
Header[] allHeaders = httpResponse.getAllHeaders();
// after the migration today
Header[] allHeaders = httpResponse.getAllHeaders();   // cannot find symbol: method getAllHeaders(), location: ClassicHttpResponse
// after this change
Header[] allHeaders = httpResponse.getHeaders();

The existing test passed because its file only imports org.apache.http.client.methods.CloseableHttpResponse, so the declaring type kept its 4.x name. This matches both names, and overrides, so calls on requests such as HttpGet, where the method is declared on AbstractHttpMessage, are renamed too. The new test fails without the YAML change.

This surfaced while validating UpgradeApacheHttpClient_5 over the 1,346 open source repositories it changes in Moderne, in a 51-repository sample compiled before and after the migration: perwendel/spark, aliyun/aliyun-dataworks-dataservice-java-sdk, onap/archive-mso-libs, king-zyd/core and Unidata/netcdf-java. Rerunning the migration with this change and recompiling, the error is gone from all but Unidata/netcdf-java, where a call on an HttpRequestBase field remained; the same shape is renamed in a unit test, so something differs in that repository's model that I have not yet found.

…ackage

UpgradeApacheHttpClient_5_DeprecatedMethods runs after the class mapping, but
renamed getAllHeaders() only on org.apache.http.HttpMessage. In a file that
uses types of the org.apache.http package itself, the package change has
already moved the method's declaring type to org.apache.hc.core5.http, so
the call kept a name HttpClient 5 does not have. Match both names, and
overrides, so calls on requests are renamed too.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant