Add null check in IndexOfKey() method
authoriSazonov <darpa@yandex.ru>
Tue, 28 Aug 2018 14:45:47 +0000 (19:45 +0500)
committeriSazonov <darpa@yandex.ru>
Tue, 28 Aug 2018 15:41:52 +0000 (20:41 +0500)
Commit migrated from https://github.com/dotnet/corefx/commit/03044f0eb5a30010114e7f526932f24f0064cc26

src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/OrderedDictionary.cs

index 07066b0..9dbe161 100644 (file)
@@ -291,9 +291,13 @@ namespace System.Collections.Specialized
 
         private int IndexOfKey(object key)
         {
-            for (int i = 0; i < objectsArray.Count; i++)
+            if (_objectsArray == null)
             {
-                object o = ((DictionaryEntry)objectsArray[i]).Key;
+                return -1;
+            }
+            for (int i = 0; i < _objectsArray.Count; i++)
+            {
+                object o = ((DictionaryEntry)_objectsArray[i]).Key;
                 if (_comparer != null)
                 {
                     if (_comparer.Equals(o, key))