Skip to content

MigratePoolingNHttpClientConnectionManager removes the imports it leaves unused - #160

Merged
knutwannheden merged 1 commit into
mainfrom
remove-leftover-imports
Oct 24, 2026
Merged

knutwannheden merged 1 commit into
mainfrom
remove-leftover-imports

Conversation

@knutwannheden

Copy link
Copy Markdown
Contributor

main went red on https://github.com/openrewrite/rewrite-apache/actions/runs/40046607973 after the rewrite snapshot carrying openrewrite/rewrite#9375, which fails a rewriteRun whose recipe output imports something nothing in the file uses. MigratePoolingNHttpClientConnectionManagerTest > migratesSimpleConstructor() reported:

A.java (changed by org.openrewrite.apache.httpclient5.MigratePoolingNHttpClientConnectionManager): import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor

The recipe replaces new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()) with PoolingAsyncClientConnectionManagerBuilder.create().build(), which drops the constructor's arguments. That argument was the file's only use of DefaultConnectingIOReactor, so its import stayed behind.

visitNewClass now schedules maybeRemoveImport for every type the dropped arguments name. RemoveImport keeps an import the file still names, so an argument that is a variable, as in the other tests, keeps its type's import. The test's after had pinned the leftover import and now omits it.

…ves unused

The builder replacement drops the constructor's arguments, so a type named
only there, such as DefaultConnectingIOReactor in
new PoolingNHttpClientConnectionManager(new DefaultConnectingIOReactor()),
kept an import nothing used. Schedule maybeRemoveImport for each type the
arguments name.
@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Oct 24, 2026
@knutwannheden
knutwannheden merged commit df37c8c into main Oct 24, 2026
2 checks passed
@knutwannheden
knutwannheden deleted the remove-leftover-imports branch October 24, 2026 01:11
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant