SpEL - comparison of zero value

I am trying to upgrade spring version from version 3.0.5 to 3.2.11.

I am having problems with SpEL when an expression compares a null value as follows:

new SpelExpressionParser().parseExpression("null < 7").getValue();    

The result of the above code results in

  • false when using version 3.0.5
  • true when using version 3.2.11, which is incorrect due to my opinion

The reason for this different behavior is that in the StandartTypeComparator class, which is used inside SpEL, there is a different implementation of the comparison method:

  • version 3.0.5

    public int compare(Object left, Object right) throws SpelEvaluationException {
    // If one is null, check if the other is
    if (left == null) {
        return right == null ? 0 : 1;
    } else if (right == null) {
        return -1; // left cannot be null
    }
    
  • version 3.2.11

    public int compare(Object left, Object right) throws SpelEvaluationException {
    // If one is null, check if the other is
    if (left == null) {
        return right == null ? 0 : -1;
    } else if (right == null) {
        return 1; // left cannot be null
    }
    

When I follow the code above, I see that the launch

new SpelExpressionParser().parseExpression("7 < null").getValue();    

will result in:

  • true when using version 3.0.5, which is incorrect, due to my opinion
  • false when using version 3.2.11

.

, - , , , , . , ?

?

- , , <, > , ==, < =, >= operator?

+4
1

, Spring.

Spring document:

/, null, : null (.. ). , (X > null ), , (X < null false).

, , :

 " first == null ? false : second == null ? false : first < second "
0

All Articles