MethodParameter strictly asserts parameter index -1 for return type

Issue: SPR-16889
This commit is contained in:
Juergen Hoeller 2018-06-14 00:42:19 +02:00
parent afa45950ff
commit c38cb43527
1 changed files with 8 additions and 1 deletions

View File

@ -227,6 +227,9 @@ public class MethodParameter {
* @since 5.0
*/
public Parameter getParameter() {
if (this.parameterIndex < 0) {
throw new IllegalStateException("Cannot retrieve Parameter descriptor for method return type");
}
Parameter parameter = this.parameter;
if (parameter == null) {
parameter = getExecutable().getParameters()[this.parameterIndex];
@ -597,6 +600,9 @@ public class MethodParameter {
*/
@Nullable
public String getParameterName() {
if (this.parameterIndex < 0) {
return null;
}
ParameterNameDiscoverer discoverer = this.parameterNameDiscoverer;
if (discoverer != null) {
String[] parameterNames = null;
@ -735,7 +741,8 @@ public class MethodParameter {
private static int validateIndex(Executable executable, int parameterIndex) {
int count = executable.getParameterCount();
Assert.isTrue(parameterIndex < count, () -> "Parameter index needs to be between -1 and " + (count - 1));
Assert.isTrue(parameterIndex >= -1 && parameterIndex < count,
() -> "Parameter index needs to be between -1 and " + (count - 1));
return parameterIndex;
}