Validate argument count for field injection #5079#5088
Validate argument count for field injection #5079#5088marcphilipp merged 6 commits intojunit-team:mainfrom
Conversation
marcphilipp
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround! I think it would be simpler to implement this in ResolverFacade.Converter#resolve(FieldContext, ExtensionContext, EvaluatedArgumentSet, int). Could you please give that a try?
|
Thanks for the review! I’ll try implementing it in ResolverFacade.Converter#resolve as you suggested. |
|
Hi @marcphilipp, I’ve made some changes based on your feedback. I’ve run the related tests, and they pass as expected. |
|
Thank you for your contribution, @jihun4452! 👍 I took a closer look and decided to move the validation to |
|
@marcphilipp |
Closes #5079
Summary
This PR adds validation for the number of provided arguments when using field injection with
@ParameterizedClass.Previously, insufficient arguments caused an
ArrayIndexOutOfBoundsExceptionwith an unclear error message.Now, a
ParameterResolutionExceptionis thrown with a clear and descriptive message.Changes
assertEnoughArgumentsForFieldInjection()to check argument count before field injectionParameterResolutionExceptionwhen insufficient arguments are providedrequiredArgumentCountForParameterFields()— computes the required argument countfirstMissingParameterFieldByIndex()— identifies the first missing fieldfailsWithMeaningfulErrorWhenTooFewArgumentsProvidedForFieldInjection()to verify error message clarityImplementation Notes
@SuppressWarnings("NullAway")for the ternary expression handlingarguments.get(), which can return a@Nullable Object[]. The null case is safely handled, but NullAway's static analysis cannot infer this guarantee@ParameterannotationsExample
Before:
After:
I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@APIannotations (N/A — internal implementation only)