From: Andrew Hoefling Date: Fri, 22 Mar 2019 02:23:53 +0000 (-0400) Subject: Updated Exception Handling for Collection (#23290) X-Git-Tag: accepted/tizen/unified/20190813.215958~55^2~25 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=01adae878ded6fe51f6def1370255d816ab42d78;p=platform%2Fupstream%2Fcoreclr.git Updated Exception Handling for Collection (#23290) * Updated Argument Helper param from list->collection since the parameter name is collection * Updated exception message to use an out of range exception that doesn't explicitly reference a list * Simplified if statements that verify if the index is out of range * Updated if logic to be simplified using (uint) * Updated exception handling to throw ThrowHelper.ThrowArgumentOutOfRange_IndexException() when the ExceptionArgument was 'Index' --- diff --git a/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs b/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs index 5d6c9c9..4898c0c 100644 --- a/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs +++ b/src/System.Private.CoreLib/shared/System/Collections/ObjectModel/Collection.cs @@ -49,7 +49,7 @@ namespace System.Collections.ObjectModel ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection); } - if (index < 0 || index >= items.Count) + if ((uint)index >= (uint)items.Count) { ThrowHelper.ThrowArgumentOutOfRange_IndexException(); } @@ -108,9 +108,9 @@ namespace System.Collections.ObjectModel ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection); } - if (index < 0 || index > items.Count) + if ((uint)index > (uint)items.Count) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert); + ThrowHelper.ThrowArgumentOutOfRange_IndexException(); } InsertItem(index, item); @@ -125,12 +125,12 @@ namespace System.Collections.ObjectModel if (collection == null) { - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); } if ((uint)index > (uint)items.Count) { - ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_ListInsert); + ThrowHelper.ThrowArgumentOutOfRange_IndexException(); } InsertItemsRange(index, collection); @@ -198,7 +198,7 @@ namespace System.Collections.ObjectModel if (collection == null) { - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.list); + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.collection); } ReplaceItemsRange(index, count, collection); @@ -211,7 +211,7 @@ namespace System.Collections.ObjectModel ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection); } - if (index < 0 || index >= items.Count) + if ((uint)index >= (uint)items.Count) { ThrowHelper.ThrowArgumentOutOfRange_IndexException(); }