Array.cs: Fixed BinarySearch when the array is empty (#77030). Added some null check...
authorSebastien Pouliot <sebastien@ximian.com>
Mon, 19 Dec 2005 15:54:00 +0000 (15:54 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Mon, 19 Dec 2005 15:54:00 +0000 (15:54 -0000)
svn path=/trunk/mcs/; revision=54604

mcs/class/corlib/System/Array.cs
mcs/class/corlib/System/ChangeLog

index ec7087aa76670afb1b684130732a22144605e8e8..895665cebd6356b75b2e8e860bb4620932725c6d 100644 (file)
@@ -8,10 +8,7 @@
 //   Gonzalo Paniagua Javier (gonzalo@ximian.com)
 //
 // (C) 2001-2003 Ximian, Inc.  http://www.ximian.com
-//
-
-//
-// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2005 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
@@ -477,33 +474,30 @@ namespace System
 
                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 @@ namespace System
                        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 @@ namespace System
                }
 
 #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 @@ namespace System
                        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 @@ namespace System
                        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 @@ namespace System
                                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."));
index 949fccf5a91efcc69053292de67e5044294ae227..78fcef7519f3527a381776815c290bc20b447906 100644 (file)
@@ -1,3 +1,8 @@
+2005-12-19  Sebastien Pouliot  <sebastien@ximian.com> 
+       * 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  <sebastien@ximian.com>
 
        * DateTime.cs: Added MonoTODO to ctor accepting a Calandar instance.