Add PowerMockWhiteboxInvokeConstructorToJavaReflection recipe#1027
Merged
Conversation
Whitebox.invokeConstructor(Class, args...) -> Constructor lookup +
newInstance() on the named class:
Constructor<MyService> c = MyService.class.getDeclaredConstructor(String.class);
c.setAccessible(true);
MyService s = c.newInstance("Alice");
Handles both the Object... varargs overload (param types resolved from the
unambiguously matched constructor, else arg.getClass()) and the explicit
Class[]/Object[] overload. Arrays passed to the Object... varargs form are
ambiguous and left unchanged. Registered in the composite.
Reuses the base hasArrayArg helper; the constructor resolution and class-literal
helpers are kept private to the recipe, matching the existing InvokeMethod
recipe (no shared-base changes).
timtebeek
approved these changes
Jun 18, 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 the final per-API recipe migrating
Whitebox.invokeConstructor(..)tojava.lang.reflect.Constructorlookup +newInstance(), registered in thePowerMockWhiteboxToJavaReflectioncomposite. Handles both theObject...varargs overload (parameter types resolved from the unambiguously matched constructor, elsearg.getClass()) and the explicitClass[]/Object[]overload. Arrays passed to theObject...form are ambiguous and left unchanged.How
Reuses the base
hasArrayArghelper; constructor resolution and class-literal helpers are kept private to the recipe, matching the existingInvokeMethodrecipe — no shared-base changes. This completesWhiteboxcoverage (setInternalState,getInternalState,invokeMethod,getField,getMethod,invokeConstructor).Tests
5 cases incl. explicit param types, bare-statement, and the
Object[]varargs no-op guard.recipeCsvValidatepasses.