Skip to content

Spring SpEL - behavioural inconsistency when using greater than (>) operator in an expression [SPR-7840] #12496

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 Dec 28, 2010 · 2 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 28, 2010

kailash pandey opened SPR-7840 and commented

While evaulating a Selection expression like -->
"#root.?[someproperty_Of_Type_X > someobject_Of_Type_X]",
where #root is a List<ApplicationObject>,

If the property on left hand side is null, then SpEL evaulates this condition as TRUE (ideally which should not be the case, u can't evaluate to true with null) and returns such underlying objects as part of Selection result.

Bigger problem arises when similar expression (as mentioned above) are tested with other operators like less than "<" or equals "==", SpEL treats them differently i.e. somehow it evaluates them as FALSE and as a result such underlying objects are eliminated from Selection result.

This is causing big problems in evaluating complex expressions and thus introducing misleading results.

Request to evaulate the problem stated above and provide solution to it .

Kailash


Affects: 3.0.2

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

Andy Clement commented

The handling for nulls does seem the wrong way round here, so I have fixed it (basically reversed it). Although I have fixed this you will still find that because 'null<SomethingNotNull' returns true (i.e. basically nothing IS less than something), if your selection involves a < then you are going to see the null entries in your result. Typically we have taken the same approach as groovy here and this groovy program will print "true, true, false" for the <'hhh' comparison:

List l = ['abc',null,'zzz']

l.each() { print it; print ' '; }
println ''
print 'gt '
l.each() {  print (it > 'hhh');print ' ';  }
print "\nlt "
l.each() { print (it < 'hhh');print ' ';  }
println "\n"

If you want to trim out the nulls, why not include that in your expression?

#root.?[someproperty_of_type_X!=null].?[someproperty_of_type_X<someobject_of_type_X]

@spring-projects-issues
Copy link
Collaborator Author

Andy Clement commented

fixed the null handling. If there is something else to look into, please raise a new jira.

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

No branches or pull requests

2 participants