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

Exception when file name is null #9

Closed
ekisielinski opened this issue Jun 12, 2020 · 5 comments
Closed

Exception when file name is null #9

ekisielinski opened this issue Jun 12, 2020 · 5 comments

Comments

@ekisielinski
Copy link

If method signature allows null string, why it throws exception?

public static string GetMimeType(string? fileName)

@khellang
Copy link
Owner

Umm. Good catch! @gfoidl I assume this shouldn't be nullable? 🤔

@ekisielinski
Copy link
Author

It depends on your design. Usually methods like TrySomething allows nulls. GetMimeType should throw ArgumentNullException for null string (because string supports Null Object Pattern - string.Empty). So I think you should remove ? from method signature.

@gfoidl
Copy link
Contributor

gfoidl commented Jun 14, 2020

Yeah, @ekisielinski is correct. We should remove the ? when null is validated and an ArgumentNullException thrown, so that the compilers knows that null isn't "tolerated".
For the Try-method null is allowed, so here the ? is correct.

Sorry, that's my fault. My brain was at a preview-stage of nullability and didn't update to the release along the way with updated guidlines on how to annotate...

@khellang
Copy link
Owner

Closed with 5d4e0de

@khellang
Copy link
Owner

v2.0.2 is now on NuGet 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants