Skip to content

Commit 072ddaa

Browse files
committed
Turn on nullability for Routing
We previously only had annotations enabled which resulted in incorrect nullability. This change enables nullability. Fixes #24042
1 parent 6f37e8a commit 072ddaa

File tree

99 files changed

+301
-251
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+301
-251
lines changed

src/Http/Http.Abstractions/src/Extensions/EndpointBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public abstract class EndpointBuilder
1414
/// <summary>
1515
/// Gets or sets the delegate used to process requests for the endpoint.
1616
/// </summary>
17-
public RequestDelegate? RequestDelegate { get; set; }
17+
public RequestDelegate RequestDelegate { get; set; } = default!;
1818

1919
/// <summary>
2020
/// Gets or sets the informational display name of this endpoint.

src/Http/Http.Abstractions/src/Routing/Endpoint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class Endpoint
2121
public Endpoint(
2222
RequestDelegate requestDelegate,
2323
EndpointMetadataCollection metadata,
24-
string displayName)
24+
string? displayName)
2525
{
2626
// All are allowed to be null
2727
RequestDelegate = requestDelegate;
@@ -32,7 +32,7 @@ public Endpoint(
3232
/// <summary>
3333
/// Gets the informational display name of this endpoint.
3434
/// </summary>
35-
public string DisplayName { get; }
35+
public string? DisplayName { get; }
3636

3737
/// <summary>
3838
/// Gets the collection of metadata associated with this endpoint.

src/Http/Routing/src/ArrayBuilder.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
// See https://github.com/dotnet/corefx/blob/143df51926f2ad397fef9c9ca7ede88e2721e801/src/Common/src/System/Collections/Generic/ArrayBuilder.cs
88

9+
#nullable disable
910

1011
using System;
1112
using System.Diagnostics;

src/Http/Routing/src/Builder/EndpointRoutingApplicationBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private static void VerifyEndpointRoutingMiddlewareIsRegistered(IApplicationBuil
128128
}
129129

130130
// If someone messes with this, just let it crash.
131-
endpointRouteBuilder = (DefaultEndpointRouteBuilder)obj;
131+
endpointRouteBuilder = (DefaultEndpointRouteBuilder)obj!;
132132

133133
// This check handles the case where Map or something else that forks the pipeline is called between the two
134134
// routing middleware.

src/Http/Routing/src/CompositeEndpointDataSource.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
55
using System.Collections.Generic;
66
using System.Collections.ObjectModel;
77
using System.Collections.Specialized;
88
using System.Diagnostics;
9+
using System.Diagnostics.CodeAnalysis;
910
using System.Linq;
1011
using System.Text;
1112
using System.Threading;
@@ -21,8 +22,8 @@ namespace Microsoft.AspNetCore.Routing
2122
public sealed class CompositeEndpointDataSource : EndpointDataSource
2223
{
2324
private readonly object _lock;
24-
private readonly ICollection<EndpointDataSource> _dataSources;
25-
private IReadOnlyList<Endpoint> _endpoints;
25+
private readonly ICollection<EndpointDataSource> _dataSources = default!;
26+
private IReadOnlyList<Endpoint> _endpoints = default!;
2627
private IChangeToken _consumerChangeToken;
2728
private CancellationTokenSource _cts;
2829

@@ -49,7 +50,7 @@ public CompositeEndpointDataSource(IEnumerable<EndpointDataSource> endpointDataS
4950
}
5051
}
5152

52-
private void OnDataSourcesChanged(object sender, NotifyCollectionChangedEventArgs e)
53+
private void OnDataSourcesChanged(object? sender, NotifyCollectionChangedEventArgs e)
5354
{
5455
lock (_lock)
5556
{
@@ -140,6 +141,7 @@ private void HandleChange()
140141
}
141142
}
142143

144+
[MemberNotNull(nameof(_cts), nameof(_consumerChangeToken))]
143145
private void CreateChangeToken()
144146
{
145147
_cts = new CancellationTokenSource();
@@ -198,7 +200,7 @@ private string DebuggerDisplayString
198200
}
199201
return sb.ToString();
200202

201-
IEnumerable<string> FormatValues(IEnumerable<KeyValuePair<string, object>> values)
203+
IEnumerable<string> FormatValues(IEnumerable<KeyValuePair<string, object?>> values)
202204
{
203205
return values.Select(
204206
kvp =>

src/Http/Routing/src/Constraints/BoolRouteConstraint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class BoolRouteConstraint : IRouteConstraint
1414
{
1515
/// <inheritdoc />
1616
public bool Match(
17-
HttpContext httpContext,
17+
HttpContext? httpContext,
1818
IRouter route,
1919
string routeKey,
2020
RouteValueDictionary values,
@@ -44,4 +44,4 @@ public bool Match(
4444
return false;
4545
}
4646
}
47-
}
47+
}

src/Http/Routing/src/Constraints/CompositeRouteConstraint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public CompositeRouteConstraint(IEnumerable<IRouteConstraint> constraints)
3333

3434
/// <inheritdoc />
3535
public bool Match(
36-
HttpContext httpContext,
36+
HttpContext? httpContext,
3737
IRouter route,
3838
string routeKey,
3939
RouteValueDictionary values,
@@ -60,4 +60,4 @@ public bool Match(
6060
return true;
6161
}
6262
}
63-
}
63+
}

src/Http/Routing/src/Constraints/DateTimeRouteConstraint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class DateTimeRouteConstraint : IRouteConstraint
2020
{
2121
/// <inheritdoc />
2222
public bool Match(
23-
HttpContext httpContext,
23+
HttpContext? httpContext,
2424
IRouter route,
2525
string routeKey,
2626
RouteValueDictionary values,
@@ -50,4 +50,4 @@ public bool Match(
5050
return false;
5151
}
5252
}
53-
}
53+
}

src/Http/Routing/src/Constraints/DecimalRouteConstraint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DecimalRouteConstraint : IRouteConstraint
1414
{
1515
/// <inheritdoc />
1616
public bool Match(
17-
HttpContext httpContext,
17+
HttpContext? httpContext,
1818
IRouter route,
1919
string routeKey,
2020
RouteValueDictionary values,
@@ -44,4 +44,4 @@ public bool Match(
4444
return false;
4545
}
4646
}
47-
}
47+
}

src/Http/Routing/src/Constraints/DoubleRouteConstraint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class DoubleRouteConstraint : IRouteConstraint
1414
{
1515
/// <inheritdoc />
1616
public bool Match(
17-
HttpContext httpContext,
17+
HttpContext? httpContext,
1818
IRouter route,
1919
string routeKey,
2020
RouteValueDictionary values,
@@ -48,4 +48,4 @@ public bool Match(
4848
return false;
4949
}
5050
}
51-
}
51+
}

0 commit comments

Comments
 (0)