-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Allow explicitly declared null in providedArgs when no argument resolver matches #35192
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,6 +218,10 @@ public void setMethodValidator(@Nullable MethodValidator methodValidator) { | |
continue; | ||
} | ||
if (!this.resolvers.supportsParameter(parameter)) { | ||
if (isParameterDeclaredButNull(parameter, providedArgs)) { | ||
args[i] = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new isParameterDeclaredButNull method checks if a parameter is explicitly set to null in providedArgs and assigns null directly, bypassing the exception. While this improves compatibility in some cases, it may hide the real cause of argument resolution failures, reducing code robustness and maintainability. |
||
continue; | ||
} | ||
throw new IllegalStateException(formatArgumentError(parameter, "No suitable resolver")); | ||
} | ||
try { | ||
|
@@ -237,6 +241,27 @@ public void setMethodValidator(@Nullable MethodValidator methodValidator) { | |
return args; | ||
} | ||
|
||
/** | ||
* If there is null in providedArgs and the paramType does not have any non-null value matching, then consider null to be explicit. | ||
*/ | ||
private boolean isParameterDeclaredButNull(MethodParameter parameter, @Nullable Object[] providedArgs) { | ||
if (ObjectUtils.isEmpty(providedArgs)) { | ||
return false; | ||
} | ||
Class<?> paramType = parameter.getParameterType(); | ||
boolean hasNull = false; | ||
for (Object arg : providedArgs) { | ||
if (arg == null) { | ||
hasNull = true; | ||
continue; | ||
} | ||
if (paramType.isAssignableFrom(arg.getClass())) { | ||
return false; | ||
} | ||
} | ||
return hasNull; | ||
} | ||
|
||
/** | ||
* Invoke the handler method with the given argument values. | ||
*/ | ||
|
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.
The test only covers the scenario where handlerMethod is null, but does not cover multiple parameters, complex types, or nested parameters. Additional tests are suggested.