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

StringReader.Read(Span<Char>) does not actually throw IOException #9798

Open
albert-du opened this issue Apr 6, 2024 · 1 comment · May be fixed by #9820
Open

StringReader.Read(Span<Char>) does not actually throw IOException #9798

albert-du opened this issue Apr 6, 2024 · 1 comment · May be fixed by #9820
Labels
area-System.IO Pri3 Indicates issues/PRs that are low priority untriaged New issue has not been triaged by the area owner

Comments

@albert-du
Copy link
Contributor

Hi,

The doc for StreamReader.Read(Span<Char>) claims that it'll throw an IOException if "the number of characters read from the stream is larger than the buffer length."

This is not true, as seen with this code:

var array = new char[8];

Span<char> span = array;

File.WriteAllText("text.txt", "0123456789");

using StreamReader reader = new("text.txt");

var result = reader.Read(span);

Console.WriteLine(result);
Console.WriteLine(span.ToString());

// 8
// 01234567

StringReader has the same behavior and is documented correctly:

// StringReader
var array = new char[8];
var span = array;

using StringReader textReader = new("0123456789");

var result = textReader.Read(span);

Console.WriteLine(result);
Console.WriteLine(span.ToString());

// 8
// 01234567

If it's welcome, I would be happy to help fix the documentation

@issues-automation issues-automation bot added the Pri3 Indicates issues/PRs that are low priority label Apr 6, 2024
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Apr 6, 2024
Copy link
Contributor

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

colejohnson66 added a commit to colejohnson66/dotnet-api-docs that referenced this issue Apr 18, 2024
Fixes dotnet#9798; Wrong documentation on `Read(Span<char>)` for `IOException`.
@colejohnson66 colejohnson66 linked a pull request Apr 18, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.IO Pri3 Indicates issues/PRs that are low priority untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant