Skip to content

Compiled elvis operator does not work correctly when default value is a complex expression [SPR-17214] #21747

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
spring-projects-issues opened this issue Aug 26, 2018 · 4 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

heyouxian opened SPR-17214 and commented

Following exception raised when I execute "record.get('MR_dlEARFCN')?:record.put('MR_dlEARFCN',expression.dl_CarrierFreq?.longValue())"

Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
 at org.springframework.asm.Frame.merge(Frame.java:1501) ~[spring-core-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.asm.Frame.merge(Frame.java:1478) ~[spring-core-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.asm.MethodWriter.visitMaxs(MethodWriter.java:1520) ~[spring-core-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.expression.spel.standard.SpelCompiler.createExpressionClass(SpelCompiler.java:175) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.expression.spel.standard.SpelCompiler.compile(SpelCompiler.java:104) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.expression.spel.standard.SpelExpression.compileExpression(SpelExpression.java:517) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.expression.spel.standard.SpelExpression.checkCompile(SpelExpression.java:487) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:372) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]

If I change expression to "record.get('MR_dlEARFCN')==null?record.put('MR_dlEARFCN',expression.dl_CarrierFreq?.longValue()):null", the following exception is raised:

Caused by: java.lang.IllegalStateException: Failed to instantiate CompiledExpression
 at org.springframework.expression.spel.standard.SpelCompiler.compile(SpelCompiler.java:110) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.expression.spel.standard.SpelExpression.compileExpression(SpelExpression.java:517) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.expression.spel.standard.SpelExpression.checkCompile(SpelExpression.java:487) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:372) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 ... 17 more
Caused by: java.lang.VerifyError: (class: spel/Ex62, method: getValue signature: (Ljava/lang/Object;Lorg/springframework/expression/EvaluationContext;)Ljava/lang/Object;) Inconsistent stack height 1 != 0
 at java.lang.Class.getDeclaredConstructors0(Native Method) ~[?:1.8.0_121]
 at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671) ~[?:1.8.0_121]
 at java.lang.Class.getConstructor0(Class.java:3075) ~[?:1.8.0_121]
 at java.lang.Class.getDeclaredConstructor(Class.java:2178) ~[?:1.8.0_121]
 at org.springframework.util.ReflectionUtils.accessibleConstructor(ReflectionUtils.java:503) ~[spring-core-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.expression.spel.standard.SpelCompiler.compile(SpelCompiler.java:107) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.expression.spel.standard.SpelExpression.compileExpression(SpelExpression.java:517) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.expression.spel.standard.SpelExpression.checkCompile(SpelExpression.java:487) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]
 at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:372) ~[spring-expression-5.0.8.RELEASE.jar:5.0.8.RELEASE]

 
I have to use "record.put('MR_dlEARFCN',record.get('MR_dlEARFCN')==null?expression.dl_CarrierFreq?.longValue():record.get('MR_dlEARFCN'))"  to make it work.


Affects: 4.3.18, 5.0.8

Backported to: 4.3.19

@spring-projects-issues
Copy link
Collaborator Author

Andy Clement commented

I have a fix for the first issue:

record.get('MR_dlEARFCN')?:record.put('MR_dlEARFCN',expression.dl_CarrierFreq?.longValue())

which caused the AIOOBE in Frame.merge() - we were not correctly entering a new compilation scope for the second part (the record.put) - this caused it to fail to put an object on the stack through which to access record.

 

However, I can't recreate the second issue yet:

record.get('MR_dlEARFCN')==null?record.put('MR_dlEARFCN',expression.dl_CarrierFreq?.longValue()):null

As that just works for me. Can you tell me the return type of your put() method - is record just a normal Map?

 

 

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Andy Clement, please roll any fix you got for the time being into master. I'll make it part of 5.1 RC3 and 5.0.9 then, leaving remaining issues to a separate follow-up ticket.

@spring-projects-issues
Copy link
Collaborator Author

Andy Clement commented

Juergen Hoeller - fix is in master for the problem I could recreate.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Backported to 5.0.9 and 4.3.19 as well now.

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.0.9 milestone Jan 11, 2019
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: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants