Skip to content

Add nullable annotations to Mvc.Core/Routing #28834

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

Merged
merged 1 commit into from
Dec 26, 2020
Merged

Conversation

pranavkm
Copy link
Contributor

Splitting up Mvc.Core into multiple PRs to make it more manageable. Once everything is updated, I'll do a cleanup to remove the pragmas from individual files.

@pranavkm pranavkm requested a review from JamesNK December 23, 2020 23:16
@pranavkm pranavkm added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Dec 23, 2020
@pranavkm pranavkm added this to the 6.0-preview1 milestone Dec 23, 2020
@pranavkm pranavkm force-pushed the prkrishn/routing-null branch from 8d94d50 to 7ad799a Compare December 25, 2020 15:24
@@ -88,7 +90,7 @@ public ActionEndpointFactory(RoutePatternTransformer routePatternTransformer, IE
endpoints.Add(builder.Build());
}

if (action.AttributeRouteInfo == null)
if (action.AttributeRouteInfo?.Template == null)
Copy link
Member

Choose a reason for hiding this comment

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

Its been a while since I looked at this code. Why add Template to this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code in the else block assumes presence of AttributeRouteInfo indicates a non-null template. The documentation appears to disagree: https://github.com/dotnet/aspnetcore/blob/master/src/Mvc/Mvc.Abstractions/src/Routing/AttributeRouteInfo.cs#L13-L16.

I don't think we produce an AttributeRouteInfo without a template configured, but this would appear to be the correct check.

@@ -63,6 +66,7 @@ public int Order
int? IRouteTemplateProvider.Order => _order;

/// <inheritdoc />
public string Name { get; set; }
[DisallowNull]
public string? Name { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

What does combining string? + DisallowNull do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It says while this could return null, you shouldn't assign a null value to it. Essentially the setter is treated as non-null

@pranavkm pranavkm merged commit 7e5588b into master Dec 26, 2020
@pranavkm pranavkm deleted the prkrishn/routing-null branch December 26, 2020 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants