-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Validate argument count for field injection #5079 #5088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate argument count for field injection #5079 #5088
Conversation
marcphilipp
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)