[Mono-bugs] [Bug 45123][Maj] New - System.Array.BinarySearch does not work properly for objects without an IComparer Interface

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Thu, 19 Jun 2003 09:22:23 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by barce@frlp.utn.edu.ar.

http://bugzilla.ximian.com/show_bug.cgi?id=45123

--- shadow/45123	Thu Jun 19 09:22:23 2003
+++ shadow/45123.tmp.19699	Thu Jun 19 09:22:23 2003
@@ -0,0 +1,87 @@
+Bug#: 45123
+Product: Mono/Class Libraries
+Version: unspecified
+OS: 
+OS Details: linux
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Major
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: barce@frlp.utn.edu.ar               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: System.Array.BinarySearch does not work properly for objects without an IComparer Interface
+
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+
+ArrayList.BinarySearch does not work properly (like MS .NET Framework) when
+looking for a Socket object.
+
+Steps to reproduce the problem:
+1. This code works with MS .NET Framework (Windows)
+
+using System;
+
+namespace ConsoleApplication2
+{
+	class Class1
+	{
+		/// <summary>
+		/// Punto de entrada principal de la aplicación.
+		/// </summary>
+		[STAThread]
+		static void Main(string[] args)
+		{
+			System.Net.Sockets.Socket socket1 = 
+				new
+System.Net.Sockets.Socket(System.Net.Sockets.AddressFamily.InterNetwork,
+				System.Net.Sockets.SocketType.Raw, System.Net.Sockets.ProtocolType.Icmp);
+
+			System.Collections.ArrayList list = new System.Collections.ArrayList(5);
+
+			list.Add(socket1);
+
+			Console.WriteLine("{0}",list.BinarySearch(socket1));
+			
+		}
+	}
+}
+
+Actual Results:
+[root@gnu tmp]# mono --debug Class1.exe
+
+Unhandled Exception: System.ArgumentException: comparer is null and value
+does not support IComparable
+in [0x00091] (at
+/mnt/disco3/home/barce/monocvs/mcs/class/corlib/System/Array.cs:410) 00
+System.Array:BinarySearch
+(System.Array,int,int,object,System.Collections.IComparer)
+in [0x0000b] (at
+/mnt/disco3/home/barce/monocvs/mcs/class/corlib/System.Collections/ArrayList.cs:638)
+00 System.Collections.ArrayList:BinarySearch
+(int,int,object,System.Collections.IComparer)
+in [0x0000a] (at
+/mnt/disco3/home/barce/monocvs/mcs/class/corlib/System.Collections/ArrayList.cs:629)
+00 System.Collections.ArrayList:BinarySearch (object)
+in [0x0001f] (at /tmp/Class1.cs:23) 00 ConsoleApplication2.Class1:Main
+(string[])
+
+
+Expected Results:
+0
+
+How often does this happen? 
+Always
+
+Additional Information:
+It seems that Mono System.Array.BinarySearch Does not like to search for an
+object without an IComparable interface. This seems correct but the MS .NET
+Framework and ROTOR do it. I looked at the ROTOR sources and instead of
+thorowing an Exception as Mono does in this case it searchs anyway using an
+external function (TrySZBinarySearch)