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

Introduce null-safe index operator in SpEL #29847

Closed

Conversation

Trympyrym
Copy link
Contributor

@Trympyrym Trympyrym commented Jan 18, 2023

Introduce SpEL support for syntax like collection?.[expr] for null-safe indexing into lists, arrays, maps, etc.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 18, 2023
@rstoyanchev rstoyanchev added the in: core Issues in core modules (aop, beans, core, context, expression) label Jan 24, 2023
@sbrannen sbrannen self-assigned this Jan 23, 2024
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 6, 2024
@sbrannen sbrannen added this to the 6.2.x milestone Feb 6, 2024
@sbrannen sbrannen changed the title SpEL: add support for null-safe get element from collection by index SpEL: introduce null-safe index operator Feb 6, 2024
@sbrannen sbrannen changed the title SpEL: introduce null-safe index operator Introduce null-safe index operator in SpEL Feb 6, 2024
@sbrannen
Copy link
Member

sbrannen commented Feb 6, 2024

Hi @Trympyrym,

Congratulations on submitting your first PR for the Spring Framework! 👍

Add to SpEL support for syntax like collection?.[expr] for null-safe get element from lists, arrays, maps, etc

We agree that we should introduce an operator for null-safe indexing; however, we are not yet convinced that ?. should be the syntax for this new operator since the . typically implies some form of property access or method invocation.

In any case, your PR is a great start, and we'll take it from here.

Thanks!

@sbrannen
Copy link
Member

sbrannen commented Mar 8, 2024

Current work on this issue can be viewed in the following feature branch.

main...sbrannen:spring-framework:issues/gh-29847-null-safe-index-operator-in-SpEL

sbrannen pushed a commit to sbrannen/spring-framework that referenced this pull request Mar 23, 2024
sbrannen added a commit to sbrannen/spring-framework that referenced this pull request Mar 23, 2024
sbrannen added a commit to sbrannen/spring-framework that referenced this pull request Mar 23, 2024
Prior to this commit, SpEL's CompoundExpression omitted the null-safe
syntax in AST string representations of indexing operations.

To address this, this commit implements isNullSafe() in Indexer.

See spring-projectsgh-29847
sbrannen added a commit to sbrannen/spring-framework that referenced this pull request Mar 23, 2024
sbrannen added a commit that referenced this pull request Mar 23, 2024
@sbrannen sbrannen closed this in 2a74fe5 Mar 23, 2024
@sbrannen
Copy link
Member

This has been merged into main in 9f4d46f and revised/extended in 4d43317, d2bd0d5, 38c473f, and 218a148.

Thanks again for kick-starting this effort! 👍

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: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants