Skip to content

Javadoc of nestingLevel parameter in MethodParameter constructor is inconsistent with actual implementation #36826

@chenlfonly

Description

@chenlfonly
/**
 * Create a new {@code MethodParameter} for the given method.
 * @param method the Method to specify a parameter for
 * @param parameterIndex the index of the parameter: -1 for the method
 * return type; 0 for the first method parameter; 1 for the second method
 * parameter, etc.
 * @param nestingLevel the nesting level of the target type
 * (typically 1; e.g. in case of a List of Lists, 1 would indicate the
 * nested List, whereas 2 would indicate the element of the nested List)
 */
public MethodParameter(Method method, int parameterIndex, int nestingLevel) {
	Assert.notNull(method, "Method must not be null");
	this.executable = method;
	this.parameterIndex = validateIndex(method, parameterIndex);
	this.nestingLevel = nestingLevel;
}

Description:
The Javadoc of the MethodParameter constructor clearly states:
In case of a List of Lists (e.g. List<List>), 1 would indicate the nested List, whereas 2 would indicate the element of the nested List
However, the implementation of getNestedParameterType() shows:
Generic nested parsing logic is only executed when this.nestingLevel > 1
When nestingLevel=1, the method directly returns the raw parameter type without any generic parsing
This causes a critical contradiction between documentation and actual behavior:
Javadoc: nestingLevel=1 = the first nested type List
Actual code: nestingLevel=1 = the outermost raw type List (no nesting parsed)

Steps to Reproduce
1、Define a method parameter: void test(List<List> list)
2、Create MethodParameter: new MethodParameter(method, 0, 1)
3、Invoke getNestedParameterType()
4、Actual return: interface java.util.List (outermost type)
5、Expected return (per javadoc): interface java.util.List (nested List type)

Is my understanding incorrect?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions