From 1b26f2fb31f43b8955c3f46663e3877c0e8343d1 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Wed, 12 Dec 2018 21:56:17 +0100 Subject: [PATCH] ParameterNameDiscoverer may return individual null entries in an array Issue: SPR-17565 (cherry picked from commit c48672c4c7c7746ef353686df3e71b637aad8052) --- .../MethodBasedEvaluationContext.java | 4 ++-- .../core/ParameterNameDiscoverer.java | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.java b/spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.java index a20446fd9c..827a4df05b 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.java +++ b/spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -101,7 +101,7 @@ public class MethodBasedEvaluationContext extends StandardEvaluationContext { } setVariable("a" + i, value); setVariable("p" + i, value); - if (paramNames != null) { + if (paramNames != null && paramNames[i] != null) { setVariable(paramNames[i], value); } } diff --git a/spring-core/src/main/java/org/springframework/core/ParameterNameDiscoverer.java b/spring-core/src/main/java/org/springframework/core/ParameterNameDiscoverer.java index 8c551f2140..ba63de5b3d 100644 --- a/spring-core/src/main/java/org/springframework/core/ParameterNameDiscoverer.java +++ b/spring-core/src/main/java/org/springframework/core/ParameterNameDiscoverer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,9 +36,11 @@ import org.springframework.lang.Nullable; public interface ParameterNameDiscoverer { /** - * Return parameter names for this method, - * or {@code null} if they cannot be determined. - * @param method method to find parameter names for + * Return parameter names for a method, or {@code null} if they cannot be determined. + *

Individual entries in the array may be {@code null} if parameter names are only + * available for some parameters of the given method but not for others. However, + * it is recommended to use stub parameter names instead wherever feasible. + * @param method the method to find parameter names for * @return an array of parameter names if the names can be resolved, * or {@code null} if they cannot */ @@ -46,9 +48,11 @@ public interface ParameterNameDiscoverer { String[] getParameterNames(Method method); /** - * Return parameter names for this constructor, - * or {@code null} if they cannot be determined. - * @param ctor constructor to find parameter names for + * Return parameter names for a constructor, or {@code null} if they cannot be determined. + *

Individual entries in the array may be {@code null} if parameter names are only + * available for some parameters of the given constructor but not for others. However, + * it is recommended to use stub parameter names instead wherever feasible. + * @param ctor the constructor to find parameter names for * @return an array of parameter names if the names can be resolved, * or {@code null} if they cannot */