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

Buffer.indexOf(ByteString) accepts negative indices #422

Open
fzhinkin opened this issue Dec 4, 2024 · 1 comment
Open

Buffer.indexOf(ByteString) accepts negative indices #422

fzhinkin opened this issue Dec 4, 2024 · 1 comment

Comments

@fzhinkin
Copy link
Collaborator

fzhinkin commented Dec 4, 2024

While Source.indexOf(ByteString) throws IllegalArgumentException on attempts to supply negative indices, Buffer's overload accepts them and return some results.

Expected behavior: Buffer.indexOf(ByteString(...), -1) should throw IAE.

@fzhinkin
Copy link
Collaborator Author

Expected behavior: Buffer.indexOf(ByteString(...), -1) should throw IAE.

If we take CharSequence.indexOf behavior as a reference, negative indices should be treated as 0.
That behavior is not the best, but the goal is providing an API that surprises as less as possible, and having similar behavior across different indexOf functions should be a step towards that goal.

@fzhinkin fzhinkin self-assigned this Dec 10, 2024
@fzhinkin fzhinkin added this to the kotlinx-io stabilization milestone Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant