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

SpEL: parsing exception when combining null-safe navigation and list indexing [SPR-16929] #21468

Closed
spring-projects-issues opened this issue Jun 11, 2018 · 6 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: superseded An issue that has been superseded by another type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

Juan Domínguez González opened SPR-16929 and commented

When parsing an expression which combines null-safe and list/array navigation it fails with a parse exception.

Example: accessing first element of a (possibly null) list/array of strings: stringList?[0]

org.springframework.expression.spel.SpelParseException: EL1041E: After parsing a valid expression, there is still more data in the expression: 'select(?[)

I'm not sure if the syntax I've used is correct, but, to me it seems the most natural one.

Combining the null safe operator and navigation using get, seems to work: e.j: stringList?.get(0)

Alternative syntaxes, such as (stringList?)[0] or stringList?.[0], also fail to compile..


Affects: 4.3.16

@spring-projects-issues spring-projects-issues added type: bug A general bug status: waiting-for-triage An issue we've not yet triaged or decided on in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues removed the type: bug A general bug label Jan 11, 2019
@sbrannen
Copy link
Member

sbrannen commented Jun 4, 2019

@aclement, ping.

@renjfk
Copy link

renjfk commented Sep 23, 2020

Well, if it's only matter of accessing null-safe first/last element listOrArray?.^[true] and listOrArray?.$[true] should do the trick as workaround.

@john-liu
Copy link

I also want this feature, to support a safe index navigation.

Just like groovy did in 3.0: use ?[] to support safe index navigation.
https://groovy-lang.org/operators.html#_safe_index_operator

@Trympyrym
Copy link
Contributor

This syntax clashes with collection selection in case of collection is context root.

Its hard to decide if ?[expr] (not collection.?[expr]) is selection by boolean expr or null-safe indexer by integer expr. Its possible when expr is boolean or int literal, but in case of ?[callSmth()] i have no idea how to implement this without great rework

@sbrannen sbrannen changed the title EL1044E when parsing expression combining null-safe and list navigation [SPR-16929] SpEL: EL1044E when parsing expression combining null-safe and list navigation [SPR-16929] Jan 18, 2023
@Trympyrym
Copy link
Contributor

However implementing syntax like stringList?.[0] seems much easier, reusing SAFE_NAVI token

@sbrannen sbrannen changed the title SpEL: EL1044E when parsing expression combining null-safe and list navigation [SPR-16929] SpEL: parsing exception when combining null-safe navigation and list indexing [SPR-16929] Jan 12, 2024
@sbrannen sbrannen self-assigned this Jan 23, 2024
@sbrannen
Copy link
Member

sbrannen commented Feb 6, 2024

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale Feb 6, 2024
@sbrannen sbrannen added type: enhancement A general enhancement status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 6, 2024
sbrannen added a commit that referenced this issue Mar 23, 2024
This set of commits introduces support for a null-safe operator in the
Spring Expression Language (SpEL), including support for compiling
expressions that use the null-safe index operator.

Note, however, that compilation is not supported for null-safe indexing
into a String or any kind of Collection (other than a List).

See gh-21468
Closes gh-29847
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: superseded An issue that has been superseded by another type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

5 participants