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

Mark or set encoding param in StreamReader ctor to be nullable #108542

Merged

Conversation

eriawan
Copy link
Member

@eriawan eriawan commented Oct 4, 2024

Fixes #106236

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

1 similar comment
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Oct 4, 2024
@eriawan
Copy link
Member Author

eriawan commented Oct 4, 2024

@jozkee please review

cc @rameel

@lilinus
Copy link
Contributor

lilinus commented Oct 4, 2024

Should the string path constructors also be modified to allow null (similar to #106658, as discussed in #2376 (comment))? I.e. the ctors below:

public StreamReader(string path, System.Text.Encoding encoding)
public StreamReader(string path, System.Text.Encoding encoding, bool detectEncodingFromByteOrderMarks)
public StreamReader(string path, System.Text.Encoding encoding, bool detectEncodingFromByteOrderMarks, int bufferSize)
public StreamReader(string path, System.Text.Encoding encoding, bool detectEncodingFromByteOrderMarks, System.IO.FileStreamOptions options)

Also; are there any tests that could be modified to verify null encoding works (and acts as UTF8)?

@rameel
Copy link

rameel commented Oct 4, 2024

Yes, as @lilinus mentioned, the constructors that accept path and encoding parameters also need to be aligned with the Stream-based constructors, similar to how it was done for StreamWriter.

@eriawan
Copy link
Member Author

eriawan commented Oct 5, 2024

Yes, as @lilinus mentioned, the constructors that accept path and encoding parameters also need to be aligned with the Stream-based constructors, similar to how it was done for StreamWriter.

thanks for the feedback! sure, I'm gong to update now.

@eriawan
Copy link
Member Author

eriawan commented Oct 5, 2024

@lilinus @rameel

Done updating the ccror with the string path as well.

@jozkee
Could you please review?

@eriawan
Copy link
Member Author

eriawan commented Oct 5, 2024

Ok, I also have done refactoring the test of StreamReader's constructor as well.

@eriawan eriawan force-pushed the streamreader_ctor_encoding_to_nullable branch from 1d796f1 to c74bd44 Compare October 9, 2024 17:15
@eriawan
Copy link
Member Author

eriawan commented Oct 10, 2024

@dotnet/area-system-io team (or area owner),

Could you review this PR? Hopefully this PR can be reviewed sooner, as it's been more than 5 days...

cc @jozkee @rameel

@eriawan
Copy link
Member Author

eriawan commented Oct 11, 2024

@dotnet/area-system-io friends, could you take a look/review here?

Also maybe you could suggest or explain why the pipeline of "runtime-dev-innerloop (Build linux-x64 debug Libraries_AllConfigurations)" is running for more than 12 hours and never ends? Or should I just close this PR?

cc @jozkee @adamsitnik

@lilinus
Copy link
Contributor

lilinus commented Oct 11, 2024

From my personal experience, it can take some time before a PR gets reviewed/merged. I imagine the team also has a lot of critical work to complete for .NET 9 they need to prioritize.

I would have patience, it is gonna get reviewed eventually 😄

@eriawan
Copy link
Member Author

eriawan commented Oct 11, 2024

From my personal experience, it can take some time before a PR gets reviewed/merged. I imagine the team also has a lot of critical work to complete for .NET 9 they need to prioritize.

I would have patience, it is gonna get reviewed eventually 😄

got it, thanks!
I usually try to remind them as well, as I have done before.

@eriawan
Copy link
Member Author

eriawan commented Oct 22, 2024

hi @dotnet/area-system-io team

Just to remind, could you please review this PR? It's been about 2 weeks now...
Thanks in advance.

cc @jozkee @adamsitnik

@eriawan eriawan force-pushed the streamreader_ctor_encoding_to_nullable branch from c74bd44 to b7a69c9 Compare October 22, 2024 20:29
@eriawan
Copy link
Member Author

eriawan commented Oct 22, 2024

Rebase this to main branch to ensure my PR is up to date as of 23rd October.

@eriawan
Copy link
Member Author

eriawan commented Oct 23, 2024

Looking at these failing checks, I think it's not caused by my PRs.

image

Especially this failed CI (of a test? ) on Regex:

image

@eriawan eriawan force-pushed the streamreader_ctor_encoding_to_nullable branch from b7a69c9 to 28c4b52 Compare October 31, 2024 20:36
@eriawan
Copy link
Member Author

eriawan commented Oct 31, 2024

rebase again with the latest main branch.

@dotnet/area-system-io team, could you please review this PR? It's been a month without any updates...

cc @jozkee @adamsitnik

@eriawan
Copy link
Member Author

eriawan commented Nov 3, 2024

rebase again with main branch as of 4th Nov.

@eriawan eriawan force-pushed the streamreader_ctor_encoding_to_nullable branch from 305cd6b to d928bea Compare December 16, 2024 15:12
@eriawan
Copy link
Member Author

eriawan commented Dec 19, 2024

Adding more unit tests to test when calling ctor that has null Encoding should not throw exception.

var ctorParamStreamEncodingBoolIntEx = Record.Exception(ctorParamStreamEncodingBoolInt);
Assert.Null(ctorParamStreamEncodingBoolIntEx);

Action ctorParamStreamEncodingBoolIntBool = () => new StreamReader(new MemoryStream(), null, false, 100, false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just call the ctor? Any exception will fail the test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Done updating the test and call the constructor instead as suggested.
Please review, @danmoseley

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests look fine, I'll let someone in the area sign off though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danmoseley
thanks! 👍

@eriawan
Copy link
Member Author

eriawan commented Dec 22, 2024

Rebase again as of 22nd Dec of main branch.

Could someone from .NET team review this PR?

@dotnet/area-system-io , @adamsitnik , @jozkee
cc @danmoseley

@eriawan eriawan force-pushed the streamreader_ctor_encoding_to_nullable branch from ba7b7a5 to c4ad463 Compare January 9, 2025 21:00
@eriawan
Copy link
Member Author

eriawan commented Jan 9, 2025

Rebase again, against main branch as of 1/10/2025.

@danmoseley Is there anything else I should do to get this PR reviewed and merged?
I hope this PR will be approved and then be merged soon, as it has been quite long (more than a month) without any further review/approval.

cc @dotnet/area-system-io , @jozkee @adamsitnik

@eriawan
Copy link
Member Author

eriawan commented Jan 9, 2025

Hmm... those failed builds of runtime (Build ios-arm64 Release AllSubsets_Mono), runtime (Build ios-arm64 Release AllSubsets_NativeAOT), untime (Build osx-x64 Release NativeAOT) and runtime (Build tvossimulator-x64 Debug AllSubsets_Mono) are not related to my changes at all, because these failed builds were ok before.

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you for your contribution @eriawan and apologies for the delay in reviews!

@@ -187,18 +187,18 @@ public StreamReader(string path, bool detectEncodingFromByteOrderMarks)
{
}

public StreamReader(string path, Encoding encoding)
public StreamReader(string path, Encoding? encoding)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was suprised to see this change, as it was not approved as part of #106236 (comment).

But then I've found @jozkee comment #106658 (review) referring to #2376 (comment) that explains that we need to unify all ctors that accept Encoding. Which we already did for StreamWriter in #106658.

So everything is good 👍

@adamsitnik adamsitnik merged commit 5abf582 into dotnet:main Jan 10, 2025
132 of 139 checks passed
@adamsitnik adamsitnik added this to the 10.0.0 milestone Jan 10, 2025
@adamsitnik adamsitnik self-assigned this Jan 10, 2025
@eriawan
Copy link
Member Author

eriawan commented Jan 10, 2025

LGTM, thank you for your contribution @eriawan and apologies for the delay in reviews!

Yayyyyy!!! Many thanks for the review, approval and the merge, @adamsitnik ! 👍

@eriawan eriawan deleted the streamreader_ctor_encoding_to_nullable branch January 10, 2025 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.IO community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StreamReader constructor documentation mismatch with implementation
6 participants