[Mono-bugs] [Bug 622101] New: Array.Sort broken when using custom comparer that sorts `null' differently.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Tue Jul 13 19:21:11 EDT 2010


http://bugzilla.novell.com/show_bug.cgi?id=622101

http://bugzilla.novell.com/show_bug.cgi?id=622101#c0


           Summary: Array.Sort broken when using custom comparer that
                    sorts `null' differently.
    Classification: Mono
           Product: Mono: Class Libraries
           Version: unspecified
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Major
          Priority: P5 - None
         Component: CORLIB
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: miguel at novell.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---
           Blocker: ---


The optimizations introduced by the suggestions in #351638 broke sorting in
cases like this:


This patch broke some things in some subtle ways.

The code that pushes the nulls to the beginning of the array assumes that this
is how the user wants the data sorted, which is not the case if he provides his
own comparer.

Consider this sample which is now broken:

using System;
using System.Collections;

class  Test {
    static void Main ()
    {
        string[] s1 = new string[9]{"Jack", "Mary", "Mike", null, "Peter",
"Boy", "Tom", null, "Allin"};
        IComparer d = new D();
        Array.Sort(s1, d);
        }
}

class D : IComparer {
        public int Compare(object x, object y)
        {
        if (x == null) return 1;
        if (y == null) return -1;
        return ((string)x).CompareTo((string)y);
        }
}

The above case should put all the null elements at the end of the array, not at
the beginning. 

This patch tries to solve this by removing the code that arbitrarily moves the
nulls to the beginning by handling those in the loops.

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list