Skip to content

Add tests for SpEL expressions on Kotlin suspending function parameters #26867

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
Tracked by #11335
eleftherias opened this issue Apr 27, 2021 · 3 comments
Closed
Tracked by #11335
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) theme: kotlin An issue related to Kotlin support type: task A general task
Milestone

Comments

@eleftherias
Copy link

Referencing parameter names in SpEL expressions fails when using Kotlin suspending functions.

For example

@Cacheable(cacheNames = ["cache"], condition = "#key.startsWith('hello')")
open suspend fun getConditionalCache(key: String): Any {
    // …

Fails with:

EL1004E: Method call: Method startsWith(java.lang.String) cannot be found on type java.lang.Object[]
org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method startsWith(java.lang.String) cannot be found on type java.lang.Object[]
	at org.springframework.expression.spel.ast.MethodReference.findAccessorForMethod(MethodReference.java:226)
	at org.springframework.expression.spel.ast.MethodReference.getValueInternal(MethodReference.java:135)
	at org.springframework.expression.spel.ast.MethodReference.access$000(MethodReference.java:55)
	at org.springframework.expression.spel.ast.MethodReference$MethodValueRef.getValue(MethodReference.java:387)
	at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:92)
	at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:117)
	at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:308)
	at org.springframework.cache.interceptor.CacheOperationExpressionEvaluator.condition(CacheOperationExpressionEvaluator.java:108)
	at org.springframework.cache.interceptor.CacheAspectSupport$CacheOperationContext.isConditionPassing(CacheAspectSupport.java:763)
	at org.springframework.cache.interceptor.CacheAspectSupport.isConditionPassing(CacheAspectSupport.java:583)
	at org.springframework.cache.interceptor.CacheAspectSupport.findCachedItem(CacheAspectSupport.java:534)
	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:402)
	at org.springframework.cache.interceptor.CacheAspectSupport.execute(CacheAspectSupport.java:345)
	at org.springframework.cache.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:64)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)

The type java.lang.Object[] comes from the suspending function, getConditionalCache, having an additional Continuation parameter that is implicitly passed to it when it is invoked.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 27, 2021
@rstoyanchev rstoyanchev added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 10, 2021
@sdeleuze sdeleuze added the theme: kotlin An issue related to Kotlin support label Jan 19, 2022
@sdeleuze sdeleuze self-assigned this Feb 8, 2023
@sdeleuze sdeleuze added this to the 6.0.6 milestone Feb 8, 2023
@sdeleuze sdeleuze added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 8, 2023
@sdeleuze sdeleuze added type: task A general task and removed type: enhancement A general enhancement labels Feb 27, 2023
@sdeleuze sdeleuze changed the title Support Kotlin suspending functions in SpEL expressions Add tests for SpEL expressions on Kotlin suspending function parameters Feb 27, 2023
@sdeleuze
Copy link
Contributor

sdeleuze commented Feb 27, 2023

This was broken at some point but seems to work now with Kotlin 1.7+, so I have just added related tests. An additional Object parameter is added by Kotlin instead transforming the last one to an array, not sure when that changed. Please provide a repro if you see it still broken.

@zzhujing
Copy link

it error also now , i use spring 6.0.8 and kotlin 1.8.22

@sdeleuze
Copy link
Contributor

@zzhujing Please provide a reproducer as an attached archive or a link to a repository in a new issue if you want us to have a look.

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) theme: kotlin An issue related to Kotlin support type: task A general task
Projects
None yet
Development

No branches or pull requests

5 participants