Skip to content

Flag un-migratable PowerMock powermock-reflect usage with a comment#1016

Merged
timtebeek merged 2 commits into
mainfrom
MBoegers/powermock-reflect-flag-unmigratable
Jun 19, 2026
Merged

Flag un-migratable PowerMock powermock-reflect usage with a comment#1016
timtebeek merged 2 commits into
mainfrom
MBoegers/powermock-reflect-flag-unmigratable

Conversation

@MBoegers

@MBoegers MBoegers commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Flags any org.powermock.reflect.Whitebox usage that the PowerMock → Mockito migration cannot rewrite, so removing the powermock-reflect dependency never silently leaves uncompilable code without a trace.

Rather than a bespoke recipe, this wires the existing declarative org.openrewrite.java.AddCommentToMethodInvocations into ReplacePowerMockito, after the Whitebox migration and before the PowerMock dependency removal:

- org.openrewrite.java.AddCommentToMethodInvocations:
    methodPattern: org.powermock.reflect.Whitebox *(..)
    comment: " PowerMock `Whitebox` call could not be automatically migrated to reflection; migrate manually "

Any remaining Whitebox call with no faithful reflection equivalent (type-based getInternalState/setInternalState, newInstance, the name-less "best guess" invokeMethod, …) gets an idempotent inline comment — AddCommentToMethodInvocations checks for an existing identical comment before adding, so repeated migration cycles don't duplicate it.

Adds an end-to-end ReplacePowerMockitoIntegrationTest case (with powermock-reflect-1 on the classpath) exercising migrate-and-flag through the full ReplacePowerMockito pipeline.

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Jun 8, 2026
@MBoegers MBoegers marked this pull request as draft June 8, 2026 13:58
Wires org.openrewrite.java.AddCommentToMethodInvocations into
ReplacePowerMockito after the Whitebox migration and before the PowerMock
dependency removal, matching `org.powermock.reflect.Whitebox *(..)`. Any
remaining Whitebox call with no faithful reflection equivalent (type-based
get/setInternalState, newInstance, name-less invokeMethod, ...) gets an
idempotent inline comment, so removing the dependency never silently
leaves uncompilable code without a trace.

Uses the existing declarative recipe rather than a bespoke one. Adds an
end-to-end ReplacePowerMockitoIntegrationTest case (with powermock-reflect-1
on the classpath) proving migrate-and-flag together.
@MBoegers MBoegers force-pushed the MBoegers/powermock-reflect-flag-unmigratable branch from 2762d71 to 787bd70 Compare June 8, 2026 14:04
@timtebeek

Copy link
Copy Markdown
Member

Given the work we've done on this front in the past week, is there anything left to flag / do here?

@timtebeek timtebeek marked this pull request as ready for review June 19, 2026 13:30
@timtebeek timtebeek merged commit a8a3615 into main Jun 19, 2026
1 check passed
@timtebeek timtebeek deleted the MBoegers/powermock-reflect-flag-unmigratable branch June 19, 2026 13:37
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Jun 19, 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.

2 participants