Skip to content
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

Passing single null value in varargs SpEL expression results in NullPointerException #27719

Closed
richardnewtonoa opened this issue Nov 22, 2021 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@richardnewtonoa
Copy link

Affected Version : 5.3.13

Worked in version : 5.3.6 (5.3.7 -> 5.3.12 not tested)

Using a Spring expression (for caching annotations) started failing for us when moving to Spring 5.3.13 from 5.3.6.

I have created a jUnit Java class test to replicate the issue
SpelEvaluation.zip
.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 22, 2021
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression labels Nov 22, 2021
@jhoeller
Copy link
Contributor

@sbrannen could this be a side effect of #27582?

@jhoeller jhoeller added this to the 5.3.14 milestone Nov 22, 2021
@richardnewtonoa
Copy link
Author

SpelEvaluation.zip
Updated the test case very slightly ... the expression results are not relevant ... the exception thrown in certain cases is the issue (at least for us)

@snicoll snicoll removed the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 22, 2021
@sbrannen
Copy link
Member

@sbrannen could this be a side effect of #27582?

Yes, that looks like it's probably a regression with regard to null handling.

@sbrannen sbrannen self-assigned this Nov 23, 2021
@sbrannen
Copy link
Member

I believe the following change (argument != null &&) in ReflectionHelper.convertArguments(...) might fix the regression, but I'd need to verify what the exact behavior was for null values before the regression.

// If the argument is null or if the argument type is equal to the varargs element
// type, there is no need to convert it or wrap it in an array. For example, using
// StringToArrayConverter to convert a String containing a comma would result in the
// String being split and repackaged in an array when it should be used as-is.
if (argument != null && !sourceType.equals(targetType.getElementTypeDescriptor())) {
	arguments[varargsPosition] = converter.convertValue(argument, sourceType, targetType);
}

sbrannen added a commit that referenced this issue Dec 10, 2021
This commit also points out that `null` supplied as a single value for
a varargs array of type Optional will be kept as `null` instead of being
converted to Optional.empty(); whereas, if more than one value is passed
to such a varargs array a null value will be properly converted to
Optional.empty().

See gh-27719
@sbrannen sbrannen changed the title java.lang.NullPointerException in ReflectionHelper with varargs SpEL expressions Passing single null value in varargs SpEL expression results in NullPointerException Dec 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

5 participants