我试图将3.0.5版本的spring版本升级到3.2.11。SpEL - 空值比较
我进入用SpeI麻烦时表达式进行比较这样的空值:在
new SpelExpressionParser().parseExpression("null < 7").getValue();
结果的上述代码结果
- 假,使用版本3.0.5时
- 真的,当使用版本3.2.11时,这是不正确的,由于我的意见
这种不同的行为的原因是,在StandartTypeComparator类,它在内部使用的规划环境地政司,也有不同的实现方法比较的:
版本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 }
版本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 }
当我看到上面的代码,我可以看到,运行
new SpelExpressionParser().parseExpression("7 < null").getValue();
将导致:
- 真实的,使用的版本3.0.5,这是不正确的,因为我的意见时
- 假的,使用的版本3.2.11时
这基本上意味着交换比较逻辑和行为的重大变化,并对我们的应用程序有很大的影响。
可能存在概念上的问题 - 比较两个值时,假设它们具有可比性,它们可以相等,小于或大于另一个。但是,在这个意义上,空值不可比较,除了空值正确吗?
这是一个错误?
当使用<,>,==,< =,> =运算符与另一个非空值比较时,空值比较曾经假设为TRUE?