Migrate AuthState to AuthExchange for HttpClient 5#130
Merged
Conversation
`AuthState` does not exist in HttpClient 5.x; it was replaced by `AuthExchange` (with `AuthProtocolState` becoming `AuthExchange.State` and `AuthOption` collapsing into `AuthScheme`). Add a `MigrateAuthState` declarative recipe to handle the type/method renames, and a `MigrateAuthSchemeCredentials` imperative recipe that: - rewrites `AuthExchange.update(BasicScheme, creds)` to `scheme.initPreemptive(creds); auth.select(scheme);` - adds an explanatory leading comment for non-`BasicScheme` `update`/`setCredentials` call sites that need human review - unwraps leftover `option.getAuthScheme()` calls (now on `AuthScheme` after the type rename) to the receiver itself
By the time `MigrateAuthState` runs, all relevant types (`AuthState`, `AuthOption`, `AuthScheme`, `BasicScheme`, `Credentials`) are now at their `org.apache.hc.client5.*` packages. That lets the recipe converge in a single cycle and lets the imperative visitor do strict argument type matching. - Move `MigrateAuthState` to run after `UpgradeApacheHttpClient_5_ClassMapping`. - Update its `ChangeType` source FQNs to the post-rename packages. - Tighten `UPDATE` matcher with explicit arg types; drop size/select defensive checks. - Reorder `MigrateAuthSchemeCredentials` to run before the new comment-adding entries so it rewrites `BasicScheme` cases first; the declarative comment recipes then only flag the call sites that survive. - Replace the imperative leading-`//` comment helper with three declarative `AddCommentToMethodInvocations` entries with shorter wording, accepting the inline `/* ... */` style. - Drop `expectedCyclesThatMakeChanges(2)` from the two tests that needed it.
Jenson3210
reviewed
May 7, 2026
Jenson3210
approved these changes
May 7, 2026
Contributor
Jenson3210
left a comment
There was a problem hiding this comment.
Single question / comment. If that does not work, also fine
…mplate` Use one multi-statement template applied at `mi.getCoordinates().replace()` so the single apply expands `update(BasicScheme, Credentials)` into `initPreemptive(...);` followed by `select(...)`. Drops the two-pass collect-then-rewrite logic and the brittle `before()`-then-`replace()` sequence (which also rebuilt `JavaParser` twice per match). Per Jente's review on PR #130.
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
AuthStatedoes not exist in HttpClient 5.x — it was replaced byAuthExchange(withAuthProtocolStatebecoming the nestedAuthExchange.Stateenum, andAuthOptioncollapsing intoAuthScheme). Before this change, the existingorg.apache.http.auth → org.apache.hc.client5.http.authpackage rename inUpgradeApacheHttpClient_5_ClassMappingwould landAuthStatereferences atorg.apache.hc.client5.http.auth.AuthState— a type that doesn't exist in 5.x.This PR adds:
MigrateAuthStatedeclarative recipe (placed beforeUpgradeApacheHttpClient_5_ClassMappingin the top-levelrecipeList) that handles:org.apache.http.auth.AuthState→org.apache.hc.client5.http.auth.AuthExchangeorg.apache.http.auth.AuthProtocolState→org.apache.hc.client5.http.auth.AuthExchange$Stateorg.apache.http.auth.AuthOption→org.apache.hc.client5.http.auth.AuthSchemeAuthExchange#setAuthScheme(AuthScheme)→select(AuthScheme)AuthExchange#setAuthOptions(Queue)→setOptions(Queue)AddCommentToMethodInvocationsmarker forAuthScheme#getCredentials()(no clean 5.x equivalent — credentials are now resolved per-request viaCredentialsProvider)MigrateAuthSchemeCredentialsimperative recipe that:AuthExchange#update(BasicScheme, Credentials)toscheme.initPreemptive(creds); auth.select(scheme);when the scheme arg's static type isBasicScheme// HttpClient 5: …leading comment for non-BasicSchemeupdate/setCredentialscall sites that need human review (the right 5.x idiom is to register credentials with aCredentialsProvideronHttpClientBuilderrather than poke them onto anAuthState)option.getAuthScheme()calls (now onAuthSchemeafter theAuthOptiontype rename) to the receiver itselfTest plan
MigrateAuthStateTest— 6 cases: type/enum/method renames,BasicSchemerewrite, non-BasicSchemeupdatecomment,setCredentialscomment,Queue<AuthOption>rename +getAuthSchemeunwrap,getCredentialscomment marker./gradlew buildpasses (full suite, recipes.csv completeness/content validation green)Notes
recipes.csvwas regenerated via./gradlew recipeCsvGenerate; the diff includes the two new entries plus some unrelated row reordering produced by the regen task.examples.ymlis intentionally left alone here; the bot run oforg.openrewrite.recipes.rewrite.OpenRewriteRecipeBestPracticeswill pick up the new@DocumentExampletest as a follow-up commit.