Skip to content

SpEL varargs behavior changed after upgrading to Spring Framework 6.1.11 #33643

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

Closed
prathmeshpethkar opened this issue Oct 3, 2024 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: invalid An issue that we don't feel is valid

Comments

@prathmeshpethkar
Copy link

prathmeshpethkar commented Oct 3, 2024

Overview

We noticed the value of the acceptedRoles changed.

With spring boot version 3.3.1 and before the size of the acceptedRoles list is 0, but after upgrading to 3.3.2 and above the value returned is 1.

TestController.java

@Value("#{T(java.util.Arrays).asList('${person.acceptedRoles}')}")
private List<String> acceptedRoles;

application.properties

person.acceptedRoles=

demo.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 3, 2024
@bclozel bclozel added the in: core Issues in core modules (aop, beans, core, context, expression) label Oct 4, 2024
@sbrannen sbrannen self-assigned this Oct 4, 2024
@sbrannen
Copy link
Member

sbrannen commented Oct 4, 2024

Hi @prathmeshpethkar,

With spring boot version 3.3.1 and before the size of the acceptedRoles list is 0, but after upgrading to 3.3.2 and above the value returned is 1.

That has always been the expected behavior, since the equivalent code in Java (Arrays.asList("")) results in a List containing a single empty string.

In Spring Framework 6.1.11, we made changes to our handling of varargs method invocations in order to support that properly.

Assuming person.acceptedRoles can be either an empty string or a comma-separated list of roles (such as ADMIN,USER), the following SpEL expression will ensure that you get an empty list or a list of the individual strings, respectively.

@Value("#{'${person.acceptedRoles}'.length > 0 ? '${person.acceptedRoles}'.split(',') : {}}")
List<String> acceptedRoles;

Please let us know if that works for you.

Thanks,

Sam

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Oct 4, 2024
@sbrannen sbrannen changed the title SPEL behavior changed after upgrading to Spring Boot 3.3.2 SpEL varargs behavior changed after upgrading to Spring Framework 6.1.11 Oct 4, 2024
@prathmeshpethkar
Copy link
Author

Thanks Sam

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Oct 5, 2024
@bclozel bclozel added status: invalid An issue that we don't feel is valid and removed status: waiting-for-feedback We need additional information before we can continue status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 5, 2024
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) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

4 participants