Bug 303509 - TaskComparator.sortByRank(...) does not sort when one of the tasks has null in RANK
Summary: TaskComparator.sortByRank(...) does not sort when one of the tasks has null i...
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Mylyn (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4.1   Edit
Assignee: Julio Gesser CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2010-02-22 11:32 EST by Julio Gesser CLA
Modified: 2010-07-28 21:30 EDT (History)
1 user (show)

See Also:


Attachments
patch soulving the problem (1.74 KB, patch)
2010-02-22 11:36 EST, Julio Gesser CLA
no flags Details | Diff
mylyn/context/zip (997 bytes, application/octet-stream)
2010-07-09 00:01 EDT, Steffen Pingel CLA
no flags Details
patch with test case (2.55 KB, text/plain)
2010-07-10 15:00 EDT, Julio Gesser CLA
no flags Details
problem solution + test case (4.43 KB, patch)
2010-07-11 09:46 EDT, Julio Gesser CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Julio Gesser CLA 2010-02-22 11:32:58 EST
Build Identifier: M20090917-0800

In TaskComparator.sortByRank(...), when one of the RANK fields from the two compared tasks are null or empty, it just return 0 (zero).

Like in other comparable fields, when the RANK is null or empty, it should be compared with the other value, because the other can be non null.

This behavior generates a wrong order in the TaskView where tasks with null in the RANK field appears in a random position.

Reproducible: Always

Steps to Reproduce:
1. Create a filter with more than 3 tasks and two of than with the field RANK as null.
2. Sort the TaskView by RANK.
3. Update the RANK field of some tasks with null to a non null value.

The order will remain the same.
Comment 1 Julio Gesser CLA 2010-02-22 11:36:06 EST
Created attachment 159812 [details]
patch soulving the problem

This patch is a possible solution to this problems.
The solution consists in convert to 0 the RANK of tasks with null. Simplifying the comparison and eliminating some ifs.
Comment 2 Steffen Pingel CLA 2010-02-22 13:53:39 EST
Shawn, is it intentional that we don't sort null values explicitly?
Comment 3 Shawn Minto CLA 2010-02-22 19:28:25 EST
This may have been intentional to support categories in a sane way since the rank value would only make sense within a query of elements with the same ranking mechanism.  When we added this support, we wanted to ensure that the original behavior was not affected by the addition of this sorting (i.e. categories were sorted by priority, but connectors with a rank could have their queries sorted by rank).  I wonder if that really makes sense though.
Comment 4 Steffen Pingel CLA 2010-07-09 00:01:50 EDT
The patch looks like the right fix to me. Julio, I'd be happy to apply it if you can provide a test case along with it.

Shawn, wouldn't this still be backwards compatible since the rank would always be equal for all tasks that do not have it set and hence the sorter would fall through to the next criterion?
Comment 5 Steffen Pingel CLA 2010-07-09 00:01:52 EDT
Created attachment 173836 [details]
mylyn/context/zip
Comment 6 Shawn Minto CLA 2010-07-09 13:55:42 EDT
After looking at this again, it seems that this should work as expected and fall through to the next criterion.
Comment 7 Julio Gesser CLA 2010-07-09 14:05:19 EDT
I will provide a patch with a test case in 
org.eclipse.mylyn.tasks.tests.TaskListSorterTest 

Currently, in this class there is a test case called:
testRankOrderSorting()

I will create a new one called:
testRankOrderSortingWithNullRank()

OK? Suggestions?
Comment 8 Shawn Minto CLA 2010-07-09 14:19:28 EDT
Sounds perfect to me.
Comment 9 Julio Gesser CLA 2010-07-10 15:00:24 EDT
Created attachment 173945 [details]
patch with test case

This patch contains a test case testing null and empty RANK sorting.
Comment 10 Julio Gesser CLA 2010-07-10 15:02:56 EDT
Patch attached in previous comment.
This patch has only the test case.
Comment 11 Steffen Pingel CLA 2010-07-11 00:18:43 EDT
Thanks. Could you create a single patch with the both the code and test case? It makes tracking the contribution in the IP log easier.
Comment 12 Julio Gesser CLA 2010-07-11 09:46:14 EDT
Created attachment 173972 [details]
problem solution + test case

Sure. Here is the patch with both solution and test case.
Thanks.
Comment 13 Steffen Pingel CLA 2010-07-28 21:29:56 EDT
Thanks Julio. I have committed the patch to head and to the e_3_4_m_3_4_x branch.