Add PowerMockWhiteboxGetFieldToJavaReflection recipe#1025
Merged
Conversation
Whitebox.getField(Class, "name") returns a reflective Field; migrate it to
Class.getDeclaredField("name") + setAccessible(true), reusing the result
variable as the local. Registered in the PowerMockWhiteboxToJavaReflection
composite.
A shared resultLocalName helper (reuse the declared result variable when the
call's result IS the reflective object) is added to WhiteboxToReflectionVisitor.
timtebeek
approved these changes
Jun 17, 2026
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.
What
Adds a per-API recipe migrating
Whitebox.getField(Class, String)toClass.getDeclaredField(String)+setAccessible(true), and registers it in thePowerMockWhiteboxToJavaReflectioncomposite. The migrated call's result is the reflectiveField, so the recipe reuses the declared result variable as the local:How
A shared
resultLocalNamehelper onWhiteboxToReflectionVisitorreturns the declared variable when present (result-is-the-object APIs likegetField/getMethod), else generates a readable name (nameField, withINCREMENT_NUMBERuniqueness).Notes
getDeclaredFielddoes not walk the class hierarchy — documented in the recipe description.Whiteboxcoverage (getField→getMethod→invokeConstructor).Tests
@DocumentExamplefor the migration plus a no-op guard confirming other Whitebox APIs are untouched.recipeCsvValidate(completeness + content) passes.