bobobear / lambdaj

Automatically exported from code.google.com/p/lambdaj
Apache License 2.0
0 stars 0 forks source link

Lambda.sort backward incompatibility #62

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
1. Have a list of objects to be sorted based on an argument value. 
Argument value is null for some of the objects.

2. Use Lambda.sort with custom comparator that handles null argument values in 
any other way than placing the relevant objects at the end of the list

3. Try 2) with version 2.3.2

4. Try 2) with version 2.1

What is the expected output? 
1) Consistent behaviour between versions 2.1 and 2.3.2
2) Objects with null argument value being sorted according to a given 
comparator.

What do you see instead?

Behaviour between version 2.1 and 2.3.2 is different. 
in 2.3.2 objects with null argument value are placed at the end automatically
in 2.1 objects with null argument value are given to the specified comparator.

What version of the product are you using? On what operating system?
2.3.2, Fedora 14

Additional info:
this code in ArgumentComparator is the source of the problem/different 
behaviour across versions:

return nullSafeCompare(
 comparator, 
 argument.evaluate(o1), 
 argument.evaluate(o2)); 

Original issue reported on code.google.com by stum...@gmail.com on 13 Apr 2011 at 11:28

GoogleCodeExporter commented 9 years ago
This change has been made on purpose in order to make comparison more robust 
and avoid lambdaj users the burden of writing null-safe comparators.

Original comment by mario.fu...@gmail.com on 24 Apr 2011 at 3:51

GoogleCodeExporter commented 9 years ago
I understand nothing much can be done about the broken backward compatibility 
any more.

But maybe it would not be bad to add this null-safety behaviour to sort() 
methods Javadoc, if I may suggest. Especially in case of sort(, Comparator) 
it's not an intuitive behaviour in my opinion.

Thank You very much, I appreciate your work

Vaclav Stumbauer

Original comment by stum...@gmail.com on 28 Apr 2011 at 11:06

GoogleCodeExporter commented 9 years ago
Lambda.sort is useless from version 2.3.2 (Ignored custom comparator in sort 
method caused a lot of problems).

Original comment by JosefM...@gmail.com on 24 May 2011 at 12:32