Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.FindIndex has incorrect ArgumentOutOfRangeException description for 'startIndex' parameter. #9719

Open
Fast-Nick opened this issue Mar 14, 2024 · 2 comments · May be fixed by #9720
Open
Labels
area-System.Runtime Pri3 Indicates issues/PRs that are low priority untriaged New issue has not been triaged by the area owner

Comments

@Fast-Nick
Copy link
Contributor

Fast-Nick commented Mar 14, 2024

Example of what it looks like today (see bottom line of documentation):

        //     .........
        // Exceptions:
        //   T:System.ArgumentNullException:
        //     array is null. -or- match is null.
        //
        //   T:System.ArgumentOutOfRangeException:
        //     startIndex is outside the range of valid indexes for array.
        public static int FindIndex<T>(T[] array, int startIndex, Predicate<T> match);

It effectively says that the method accepts [0 <= startIndex < Length] with Length exclusive.
But what the method actually accepts is [0 <= startIndex <= Length] with Length inclusive.

The real behavior of the startIndex is identical to String.Substring, which has the following description instead:

        //   T:System.ArgumentOutOfRangeException:
        //     startIndex is less than zero or greater than the length of this instance.

To be correct and easy to understand the FindIndex documentation should thus say:

        //     startIndex is less than zero or greater than the length of the array.
@issues-automation issues-automation bot added the Pri3 Indicates issues/PRs that are low priority label Mar 14, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Mar 14, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-runtime

Fast-Nick added a commit to Fast-Nick/dotnet-api-docs that referenced this issue Mar 14, 2024
…startIndex' parameter on FindIndex methods

Changed it to match String.Substring, because the behavior is identical (and original description is arguably wrong or hard to understand).

Fixes: dotnet#9719
@Fast-Nick
Copy link
Contributor Author

Adding a draft for now - it does fix the exact issue described, but the phrase "... is outside the range of valid indexes for ..." exists on a lot of other Array methods too, so it's probably ideal to go through all of them and make sure the phrasing is consistent for all methods which have this bound-check behavior.

...but I don't have time to do that today so will look at it / go through all methods later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Runtime Pri3 Indicates issues/PRs that are low priority untriaged New issue has not been triaged by the area owner
Projects
None yet
1 participant