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

Doc: SpEL behavior when comparing value to null [SPR-14361] #18933

Closed
spring-projects-issues opened this issue Jun 14, 2016 · 2 comments
Closed

Doc: SpEL behavior when comparing value to null [SPR-14361] #18933

spring-projects-issues opened this issue Jun 14, 2016 · 2 comments

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jun 14, 2016

Marko Talijanac opened SPR-14361 and commented

When in SpEL a number is compared to null, a result is interpreted as "null is always the lowest number". Behavior is unexpected and undocumented.

As null is not a number expected behavior would be either exception or false in all cases except when comparing with other null value.

For example expression "x == null && x < 100" should always yield false (or raise exception) as x is either null or a number with a value.

Behavior is not overridable with user provided TypeComparator (except by throwing exception from TypeComparator) as operators never invoke TypeComparator#canCompare method, and always flatten comparator result of (-1,0,1) to true|false result.

Also current behaviour is not consistent with past spring versions. See this stack overflow question

{{examples of popular comparisons
null == null => true

null < 1 => true
1 > null => true
null <= 1 => true
1 >= null => true

null < -1 => true
-1 > null => true
null <= -1 => true
-1 >= null => true

null > 1 => false
1 < null => false
null >= 1 => false
1 <= null => false

null > -1 => false
-1 < null => false
null >= -1 => false
-1 <= null => false}}


Affects: 3.2.16, 4.3 GA

Issue Links:

  • #12496 Spring SpEL - behavioural inconsistency when using greater than (>) operator in an expression
  • #19553 SpEL and Date Literals

Referenced from: commits 6bdc5bf, 05579fd, 5ccc8e3, c22cad1

Backported to: 4.2.9, 3.2.18

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 14, 2016

Marko Talijanac commented

Suggestion are:

  • document current behavior
  • implement behavior "compare with null always yields false"
  • allow user to override operator behavior
@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 22, 2016

Juergen Hoeller commented

This seems to have been an intentional change back in 3.1: #12496. Andy Clement, assigning this to you for further clarification.

From my perspective, let's rather document the behavior as it is, since the change of behavior was actually between 3.0 and 3.1... far back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.