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

Bug: Inconsistent behavior of Indexof() and LastIndexOf() #62

Open
NightOwl888 opened this issue Dec 24, 2023 · 0 comments
Open

Bug: Inconsistent behavior of Indexof() and LastIndexOf() #62

NightOwl888 opened this issue Dec 24, 2023 · 0 comments
Labels
is:bug Something isn't working pri:normal
Milestone

Comments

@NightOwl888
Copy link
Owner

We need our own implementations of IndexOf() and LastIndexOf() on StringBuilder because they are not provided in .NET.

The J2N implementations we have account for Ordinal and OrdinalIgnoreCase of StringComparison, but all other options call ToString() on the StringBuilder and then cascade the call to string.IndexOf() and string.LastIndexOf().

However, in the JDK and Apache Harmony, the overload that allows you to specify startIndex/fromIndex do not have any exceptions thrown on the bounds and instead correct anything over Length - 1 to be equivalent to Length - 1 and anything below zero will return -1. So, this behavior is inconsistent between Java and .NET.

However, we have no way to re-implement IndexOf() and LastIndexOf() on String or ReadOnlySpan<char> so the most logical thing to do is to change the Ordinal and OrdinalIgnoreCase to throw when Length is passed so it is consistent with the rest of the .NET behavior. The only downside is that this means that any logic written in Java that is sloppy with the bounds will need to be corrected. However, we could simply provide a note in the API docs that the behavior is inconsistent with Java and consistent with .NET.

Whatever the fix, it will require a breaking behavior change and cannot be addressed without a major version bump.

@NightOwl888 NightOwl888 added is:bug Something isn't working pri:normal labels Dec 24, 2023
@NightOwl888 NightOwl888 added this to the 3.0 milestone Dec 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:bug Something isn't working pri:normal
Projects
None yet
Development

No branches or pull requests

1 participant