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

Feat/enable nullable reference types core #52

Merged
merged 20 commits into from
Apr 19, 2024

Conversation

Dovchik
Copy link
Contributor

@Dovchik Dovchik commented Apr 11, 2024

First part of enabling null ref types. I will split the PR into different part for each service.

@Dovchik Dovchik changed the title Feat/enable nullable reference types Feat/enable nullable reference types core Apr 11, 2024
@Dovchik Dovchik marked this pull request as ready for review April 11, 2024 10:17
Copy link

@asein-sinch asein-sinch left a comment

Choose a reason for hiding this comment

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

Can you add some tests for the parts where the behavior is changed?


ISinchAuth auth =
new OAuth(_keyId, _keySecret, _httpClient, _loggerFactory?.Create<OAuth>(),
new OAuth(_keyId!, _keySecret!, _httpClient, _loggerFactory?.Create<OAuth>(),

Choose a reason for hiding this comment

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

I'm not sure about using the null-forgiving operator here as apart from logging a warning, there is no guarantee to have a non-null value at this point

Copy link
Contributor Author

Choose a reason for hiding this comment

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

src/Sinch/SinchClient.cs Outdated Show resolved Hide resolved

return new SmsClient(
new ProjectId(
_projectId!), // exception is throw when trying to get SMS client property if _projectId is null

Choose a reason for hiding this comment

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

It's strange to say that you are sure the _projectId is not null here but comment that is may still be null and it would be handled later on in the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Null forgiving operator (!) is not about to be sure something is not null, but to suppress warnings which is necessary for the case - same applies to the OAuth. Null refs is just another tools analysis and not a panacea to fix null ref exceptions, unfortunately

Choose a reason for hiding this comment

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

The goal of the ! is to override the compiler analysis so that it would not issue a warning.
If I look at the SmsClient constructor, I see that ProjectId is a record which expects a non-null value. As there is no check here that prevents the _projectId variable to be null, maybe it would be clearer to set the record parameter as nullable such as string? Value and handle the null-value case in the SmsClient constructor before initializing the API classes (Batches, Inbounds...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is by design, specific clients needs no nulls to function properly, but the caller is responsible for that and manages delayed/null initialization

src/Sinch/Core/JsonInterfaceConverter.cs Outdated Show resolved Hide resolved
src/Sinch/Core/JsonInterfaceConverter.cs Show resolved Hide resolved
src/Sinch/Auth/ApplicationSignedAuth.cs Show resolved Hide resolved
@Dovchik Dovchik requested a review from asein-sinch April 17, 2024 14:48
@Dovchik
Copy link
Contributor Author

Dovchik commented Apr 18, 2024

Can you add some tests for the parts where the behavior is changed?

Added test for JsonInterfaceConverter

@Dovchik Dovchik merged commit 8bd6c13 into main Apr 19, 2024
3 checks passed
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

Successfully merging this pull request may close these issues.

2 participants