Author: spouliot
Date: 2005-12-19 10:54:00 -0500 (Mon, 19 Dec 2005)
New Revision: 54604

Modified:
   trunk/mcs/class/corlib/System/Array.cs
   trunk/mcs/class/corlib/System/ChangeLog
Log:
Array.cs: Fixed BinarySearch when the array is empty (#77030). Added some null 
check which throws ArgumentNullException under 2.0.

Modified: trunk/mcs/class/corlib/System/Array.cs
===================================================================
--- trunk/mcs/class/corlib/System/Array.cs      2005-12-19 14:52:37 UTC (rev 
54603)
+++ trunk/mcs/class/corlib/System/Array.cs      2005-12-19 15:54:00 UTC (rev 
54604)
@@ -8,11 +8,8 @@
 //   Gonzalo Paniagua Javier ([EMAIL PROTECTED])
 //
 // (C) 2001-2003 Ximian, Inc.  http://www.ximian.com
+// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
 //
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
-//
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // "Software"), to deal in the Software without restriction, including
@@ -477,33 +474,30 @@
 
                public static Array CreateInstance (Type elementType, params 
long [] lengths)
                {
-                       if (lengths == null) {
-                               // LAMESPEC: Docs say we should throw a 
ArgumentNull, but .NET
-                               // 1.1 actually throws a NullReference.
-                               throw new NullReferenceException 
(Locale.GetText ("'lengths' cannot be null."));
-                       }
+#if NET_2_0
+                       if (lengths == null)
+                               throw new ArgumentNullException ("lengths");
+#endif
                        return CreateInstance (elementType, GetIntArray 
(lengths));
                }
 
                [ComVisible (false)]
                public object GetValue (params long [] indices)
                {
-                       if (indices == null) {
-                               // LAMESPEC: Docs say we should throw a 
ArgumentNull, but .NET
-                               // 1.1 actually throws a NullReference.
-                               throw new NullReferenceException 
(Locale.GetText ("'indices' cannot be null."));
-                       }
+#if NET_2_0
+                       if (indices == null)
+                               throw new ArgumentNullException ("indices");
+#endif
                        return GetValue (GetIntArray (indices));
                }
 
                [ComVisible (false)]
                public void SetValue (object value, params long [] indices)
                {
-                       if (indices == null) {
-                               // LAMESPEC: Docs say we should throw a 
ArgumentNull, but .NET
-                               // 1.1 actually throws a NullReference.
-                               throw new NullReferenceException 
(Locale.GetText ("'indices' cannot be null."));
-                       }
+#if NET_2_0
+                       if (indices == null)
+                               throw new ArgumentNullException ("indices");
+#endif
                        SetValue (value, GetIntArray (indices));
                }
 #endif
@@ -522,6 +516,9 @@
                        if (array.Rank > 1)
                                throw new RankException (Locale.GetText ("Only 
single dimension arrays are supported."));
 
+                       if (array.Length == 0)
+                               return -1;
+
                        if (!(value is IComparable))
                                throw new ArgumentException (Locale.GetText 
("value does not support IComparable."));
 
@@ -529,7 +526,7 @@
                }
 
 #if NET_2_0
-       [ReliabilityContractAttribute (Consistency.WillNotCorruptState, 
Cer.MayFail)]
+               [ReliabilityContractAttribute (Consistency.WillNotCorruptState, 
Cer.MayFail)]
 #endif
                public static int BinarySearch (Array array, object value, 
IComparer comparer)
                {
@@ -539,6 +536,9 @@
                        if (array.Rank > 1)
                                throw new RankException (Locale.GetText ("Only 
single dimension arrays are supported."));
 
+                       if (array.Length == 0)
+                               return -1;
+
                        if ((comparer == null) && (value != null) && !(value is 
IComparable))
                                throw new ArgumentException (Locale.GetText (
                                        "comparer is null and value does not 
support IComparable."));
@@ -567,6 +567,10 @@
                        if (index > array.GetLowerBound (0) + array.GetLength 
(0) - length)
                                throw new ArgumentException (Locale.GetText (
                                        "index and length do not specify a 
valid range in array."));
+
+                       if (array.Length == 0)
+                               return -1;
+
                        if ((value != null) && (!(value is IComparable)))
                                throw new ArgumentException (Locale.GetText (
                                        "value does not support IComparable"));
@@ -596,6 +600,9 @@
                                throw new ArgumentException (Locale.GetText (
                                        "index and length do not specify a 
valid range in array."));
 
+                       if (array.Length == 0)
+                               return -1;
+
                        if ((comparer == null) && (value != null) && !(value is 
IComparable))
                                throw new ArgumentException (Locale.GetText (
                                        "comparer is null and value does not 
support IComparable."));

Modified: trunk/mcs/class/corlib/System/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System/ChangeLog     2005-12-19 14:52:37 UTC (rev 
54603)
+++ trunk/mcs/class/corlib/System/ChangeLog     2005-12-19 15:54:00 UTC (rev 
54604)
@@ -1,3 +1,8 @@
+2005-12-19  Sebastien Pouliot  <[EMAIL PROTECTED]> 
+ 
+       * Array.cs: Fixed BinarySearch when the array is empty (#77030). Added
+       some null check which throws ArgumentNullException under 2.0.
+
 2005-12-15  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * DateTime.cs: Added MonoTODO to ctor accepting a Calandar instance.

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to