[Mono-bugs] [Bug 368455] New: ArrayList.Sort() throws exception with incorrect message
bugzilla_noreply at novell.com
bugzilla_noreply at novell.com
Sat Mar 8 11:27:11 EST 2008
https://bugzilla.novell.com/show_bug.cgi?id=368455
Summary: ArrayList.Sort() throws exception with incorrect message
Product: Mono: Class Libraries
Version: 1.2.6
Platform: i686
OS/Version: Linux
Status: NEW
Severity: Normal
Priority: P5 - None
Component: System
AssignedTo: mono-bugs at lists.ximian.com
ReportedBy: dbera.web at gmail.com
QAContact: mono-bugs at lists.ximian.com
Found By: Customer
Trying to use an ArrayList of objects that defines a generic IComparer<T> (but
not IComparable) and then sorting the list crashes as expected (as I was told
in the IRC). However, the error message says "No IComparable or IComparable<T>
interface found for..." which is incorrect and confusing since the objects
clearly implement IComparable<T>.
$ cat testlist.cs
using System;
using System.Collections.Generic;
class test {
class obj : IComparable<obj> {
public int CompareTo (obj other)
{
return 1;
}
}
public static void Main ()
{
System.Collections.ArrayList list = new System.Collections.ArrayList
();
list.Add (new obj ());
list.Add (new obj ());
list.Sort ();
}
}
$ mono testlist.exe
Unhandled Exception: System.InvalidOperationException: The comparer threw an
exception. ---> System.InvalidOperationException: No IComparable or
IComparable<T> interface found for type 'System.Object'.
at System.Array.compare[Object] (System.Object value1, System.Object value2,
IComparer`1 comparer) [0x00000]
at System.Array.qsort[Object,Object] (System.Object[] keys, System.Object[]
items, Int32 low0, Int32 high0, IComparer`1 comparer) [0x00000]
at System.Array.Sort[Object,Object] (System.Object[] keys, System.Object[]
items, Int32 index, Int32 length, IComparer`1 comparer) [0x00000] --- End of
inner exception stack trace ---
at System.Array.Sort[Object,Object] (System.Object[] keys, System.Object[]
items, Int32 index, Int32 length, IComparer`1 comparer) [0x00000]
at System.Array.Sort[Object] (System.Object[] array, Int32 index, Int32
length) [0x00000]
at System.Collections.ArrayList.Sort () [0x00000]
at test.Main () [0x00000]
--
Configure bugmail: https://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