diff --git a/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java index c91aea87a..9c7013b7c 100644 --- a/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java +++ b/core/src/main/java/org/apache/struts2/interceptor/parameter/ParametersInterceptor.java @@ -399,8 +399,11 @@ public class ParametersInterceptor extends MethodFilterInterceptor { if (relevantMethod == null) { return false; } - StrutsParameter annotation = getParameterAnnotation(relevantMethod); - if (annotation == null || annotation.depth() < paramDepth) { + if (getPermittedInjectionDepth(relevantMethod) < paramDepth) { + LOG.debug( + "Parameter injection for method [{}] on action [{}] rejected. Ensure it is annotated with @StrutsParameter with an appropriate 'depth'.", + relevantMethod.getName(), + relevantMethod.getDeclaringClass().getName()); return false; } if (paramDepth >= 1) { @@ -450,8 +453,11 @@ public class ParametersInterceptor extends MethodFilterInterceptor { if (!Modifier.isPublic(field.getModifiers())) { return false; } - StrutsParameter annotation = getParameterAnnotation(field); - if (annotation == null || annotation.depth() < paramDepth) { + if (getPermittedInjectionDepth(field) < paramDepth) { + LOG.debug( + "Parameter injection for field [{}] on action [{}] rejected. Ensure it is annotated with @StrutsParameter with an appropriate 'depth'.", + fieldName, + action.getClass().getName()); return false; } if (paramDepth >= 1) { @@ -467,6 +473,17 @@ public class ParametersInterceptor extends MethodFilterInterceptor { allowlistParameterizedTypeArg(field.getGenericType()); } + /** + * @return permitted injection depth where -1 indicates not permitted + */ + protected int getPermittedInjectionDepth(AnnotatedElement element) { + StrutsParameter annotation = getParameterAnnotation(element); + if (annotation == null) { + return -1; + } + return annotation.depth(); + } + /** * Annotation retrieval logic. Can be overridden to support extending annotations or some other form of annotation * inheritance.