Skip to content

Commit d739000

Browse files
committed
Enable nullable on generated code
1 parent ae2aaa0 commit d739000

File tree

9 files changed

+113
-97
lines changed

9 files changed

+113
-97
lines changed

src/Servers/Kestrel/Core/src/Internal/Http/HttpHeaders.Generated.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
using Microsoft.Net.Http.Headers;
1313
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure;
1414

15+
#nullable enable
16+
1517
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
1618
{
1719
internal enum KnownHeaderType
@@ -6712,7 +6714,7 @@ protected override bool CopyToFast(KeyValuePair<string, StringValues>[] array, i
67126714
array[arrayIndex] = new KeyValuePair<string, StringValues>(HeaderNames.ContentLength, HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value));
67136715
++arrayIndex;
67146716
}
6715-
((ICollection<KeyValuePair<string, StringValues>>)MaybeUnknown)?.CopyTo(array, arrayIndex);
6717+
((ICollection<KeyValuePair<string, StringValues>>?)MaybeUnknown)?.CopyTo(array, arrayIndex);
67166718

67176719
return true;
67186720
}
@@ -12724,7 +12726,7 @@ protected override bool CopyToFast(KeyValuePair<string, StringValues>[] array, i
1272412726
array[arrayIndex] = new KeyValuePair<string, StringValues>(HeaderNames.ContentLength, HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value));
1272512727
++arrayIndex;
1272612728
}
12727-
((ICollection<KeyValuePair<string, StringValues>>)MaybeUnknown)?.CopyTo(array, arrayIndex);
12729+
((ICollection<KeyValuePair<string, StringValues>>?)MaybeUnknown)?.CopyTo(array, arrayIndex);
1272812730

1272912731
return true;
1273012732
}
@@ -12816,7 +12818,7 @@ internal unsafe void CopyToFast(ref BufferWriter<PipeWriter> output)
1281612818
{
1281712819
tempBits ^= 0x8000000000000000L;
1281812820
output.Write(HeaderBytes.Slice(640, 18));
12819-
output.WriteNumeric((ulong)ContentLength.Value);
12821+
output.WriteNumeric((ulong)ContentLength.GetValueOrDefault());
1282012822
if (tempBits == 0)
1282112823
{
1282212824
return;
@@ -13266,10 +13268,10 @@ private struct HeaderReferences
1326613268
public StringValues _AccessControlExposeHeaders;
1326713269
public StringValues _AccessControlMaxAge;
1326813270

13269-
public byte[] _rawConnection;
13270-
public byte[] _rawDate;
13271-
public byte[] _rawTransferEncoding;
13272-
public byte[] _rawServer;
13271+
public byte[]? _rawConnection;
13272+
public byte[]? _rawDate;
13273+
public byte[]? _rawTransferEncoding;
13274+
public byte[]? _rawServer;
1327313275
}
1327413276

1327513277
public partial struct Enumerator
@@ -14149,7 +14151,7 @@ protected override bool CopyToFast(KeyValuePair<string, StringValues>[] array, i
1414914151
array[arrayIndex] = new KeyValuePair<string, StringValues>(HeaderNames.ContentLength, HeaderUtilities.FormatNonNegativeInt64(_contentLength.Value));
1415014152
++arrayIndex;
1415114153
}
14152-
((ICollection<KeyValuePair<string, StringValues>>)MaybeUnknown)?.CopyTo(array, arrayIndex);
14154+
((ICollection<KeyValuePair<string, StringValues>>?)MaybeUnknown)?.CopyTo(array, arrayIndex);
1415314155

1415414156
return true;
1415514157
}
@@ -14219,4 +14221,4 @@ public bool MoveNext()
1421914221
}
1422014222
}
1422114223
}
14222-
}
14224+
}

src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.Generated.cs

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,44 @@
99
using Microsoft.AspNetCore.Http.Features.Authentication;
1010
using Microsoft.AspNetCore.Server.Kestrel.Core.Features;
1111

12+
#nullable enable
13+
1214
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
1315
{
1416
internal partial class HttpProtocol : IFeatureCollection
1517
{
16-
private object _currentIHttpRequestFeature;
17-
private object _currentIHttpRequestBodyDetectionFeature;
18-
private object _currentIHttpResponseFeature;
19-
private object _currentIHttpResponseBodyFeature;
20-
private object _currentIRequestBodyPipeFeature;
21-
private object _currentIHttpRequestIdentifierFeature;
22-
private object _currentIServiceProvidersFeature;
23-
private object _currentIHttpRequestLifetimeFeature;
24-
private object _currentIHttpConnectionFeature;
25-
private object _currentIRouteValuesFeature;
26-
private object _currentIEndpointFeature;
27-
private object _currentIHttpAuthenticationFeature;
28-
private object _currentIHttpRequestTrailersFeature;
29-
private object _currentIQueryFeature;
30-
private object _currentIFormFeature;
31-
private object _currentIHttpUpgradeFeature;
32-
private object _currentIHttp2StreamIdFeature;
33-
private object _currentIHttpResponseTrailersFeature;
34-
private object _currentIResponseCookiesFeature;
35-
private object _currentIItemsFeature;
36-
private object _currentITlsConnectionFeature;
37-
private object _currentIHttpWebSocketFeature;
38-
private object _currentISessionFeature;
39-
private object _currentIHttpMaxRequestBodySizeFeature;
40-
private object _currentIHttpMinRequestBodyDataRateFeature;
41-
private object _currentIHttpMinResponseDataRateFeature;
42-
private object _currentIHttpBodyControlFeature;
43-
private object _currentIHttpResetFeature;
18+
private object? _currentIHttpRequestFeature;
19+
private object? _currentIHttpRequestBodyDetectionFeature;
20+
private object? _currentIHttpResponseFeature;
21+
private object? _currentIHttpResponseBodyFeature;
22+
private object? _currentIRequestBodyPipeFeature;
23+
private object? _currentIHttpRequestIdentifierFeature;
24+
private object? _currentIServiceProvidersFeature;
25+
private object? _currentIHttpRequestLifetimeFeature;
26+
private object? _currentIHttpConnectionFeature;
27+
private object? _currentIRouteValuesFeature;
28+
private object? _currentIEndpointFeature;
29+
private object? _currentIHttpAuthenticationFeature;
30+
private object? _currentIHttpRequestTrailersFeature;
31+
private object? _currentIQueryFeature;
32+
private object? _currentIFormFeature;
33+
private object? _currentIHttpUpgradeFeature;
34+
private object? _currentIHttp2StreamIdFeature;
35+
private object? _currentIHttpResponseTrailersFeature;
36+
private object? _currentIResponseCookiesFeature;
37+
private object? _currentIItemsFeature;
38+
private object? _currentITlsConnectionFeature;
39+
private object? _currentIHttpWebSocketFeature;
40+
private object? _currentISessionFeature;
41+
private object? _currentIHttpMaxRequestBodySizeFeature;
42+
private object? _currentIHttpMinRequestBodyDataRateFeature;
43+
private object? _currentIHttpMinResponseDataRateFeature;
44+
private object? _currentIHttpBodyControlFeature;
45+
private object? _currentIHttpResetFeature;
4446

4547
private int _featureRevision;
4648

47-
private List<KeyValuePair<Type, object>> MaybeExtra;
49+
private List<KeyValuePair<Type, object>>? MaybeExtra;
4850

4951
private void FastReset()
5052
{
@@ -87,7 +89,7 @@ internal void ResetFeatureCollection()
8789
_featureRevision++;
8890
}
8991

90-
private object ExtraFeatureGet(Type key)
92+
private object? ExtraFeatureGet(Type key)
9193
{
9294
if (MaybeExtra == null)
9395
{
@@ -126,11 +128,11 @@ private void ExtraFeatureSet(Type key, object value)
126128

127129
int IFeatureCollection.Revision => _featureRevision;
128130

129-
object IFeatureCollection.this[Type key]
131+
object? IFeatureCollection.this[Type key]
130132
{
131133
get
132134
{
133-
object feature = null;
135+
object? feature = null;
134136
if (key == typeof(IHttpRequestFeature))
135137
{
136138
feature = _currentIHttpRequestFeature;
@@ -369,129 +371,129 @@ object IFeatureCollection.this[Type key]
369371
}
370372
else
371373
{
372-
ExtraFeatureSet(key, value);
374+
ExtraFeatureSet(key, value!); // TODO: What happens if you set an extra feature with a null value?
373375
}
374376
}
375377
}
376378

377379
TFeature IFeatureCollection.Get<TFeature>()
378380
{
379-
TFeature feature = default;
381+
TFeature? feature = default;
380382
if (typeof(TFeature) == typeof(IHttpRequestFeature))
381383
{
382-
feature = (TFeature)_currentIHttpRequestFeature;
384+
feature = (TFeature?)_currentIHttpRequestFeature;
383385
}
384386
else if (typeof(TFeature) == typeof(IHttpRequestBodyDetectionFeature))
385387
{
386-
feature = (TFeature)_currentIHttpRequestBodyDetectionFeature;
388+
feature = (TFeature?)_currentIHttpRequestBodyDetectionFeature;
387389
}
388390
else if (typeof(TFeature) == typeof(IHttpResponseFeature))
389391
{
390-
feature = (TFeature)_currentIHttpResponseFeature;
392+
feature = (TFeature?)_currentIHttpResponseFeature;
391393
}
392394
else if (typeof(TFeature) == typeof(IHttpResponseBodyFeature))
393395
{
394-
feature = (TFeature)_currentIHttpResponseBodyFeature;
396+
feature = (TFeature?)_currentIHttpResponseBodyFeature;
395397
}
396398
else if (typeof(TFeature) == typeof(IRequestBodyPipeFeature))
397399
{
398-
feature = (TFeature)_currentIRequestBodyPipeFeature;
400+
feature = (TFeature?)_currentIRequestBodyPipeFeature;
399401
}
400402
else if (typeof(TFeature) == typeof(IHttpRequestIdentifierFeature))
401403
{
402-
feature = (TFeature)_currentIHttpRequestIdentifierFeature;
404+
feature = (TFeature?)_currentIHttpRequestIdentifierFeature;
403405
}
404406
else if (typeof(TFeature) == typeof(IServiceProvidersFeature))
405407
{
406-
feature = (TFeature)_currentIServiceProvidersFeature;
408+
feature = (TFeature?)_currentIServiceProvidersFeature;
407409
}
408410
else if (typeof(TFeature) == typeof(IHttpRequestLifetimeFeature))
409411
{
410-
feature = (TFeature)_currentIHttpRequestLifetimeFeature;
412+
feature = (TFeature?)_currentIHttpRequestLifetimeFeature;
411413
}
412414
else if (typeof(TFeature) == typeof(IHttpConnectionFeature))
413415
{
414-
feature = (TFeature)_currentIHttpConnectionFeature;
416+
feature = (TFeature?)_currentIHttpConnectionFeature;
415417
}
416418
else if (typeof(TFeature) == typeof(IRouteValuesFeature))
417419
{
418-
feature = (TFeature)_currentIRouteValuesFeature;
420+
feature = (TFeature?)_currentIRouteValuesFeature;
419421
}
420422
else if (typeof(TFeature) == typeof(IEndpointFeature))
421423
{
422-
feature = (TFeature)_currentIEndpointFeature;
424+
feature = (TFeature?)_currentIEndpointFeature;
423425
}
424426
else if (typeof(TFeature) == typeof(IHttpAuthenticationFeature))
425427
{
426-
feature = (TFeature)_currentIHttpAuthenticationFeature;
428+
feature = (TFeature?)_currentIHttpAuthenticationFeature;
427429
}
428430
else if (typeof(TFeature) == typeof(IHttpRequestTrailersFeature))
429431
{
430-
feature = (TFeature)_currentIHttpRequestTrailersFeature;
432+
feature = (TFeature?)_currentIHttpRequestTrailersFeature;
431433
}
432434
else if (typeof(TFeature) == typeof(IQueryFeature))
433435
{
434-
feature = (TFeature)_currentIQueryFeature;
436+
feature = (TFeature?)_currentIQueryFeature;
435437
}
436438
else if (typeof(TFeature) == typeof(IFormFeature))
437439
{
438-
feature = (TFeature)_currentIFormFeature;
440+
feature = (TFeature?)_currentIFormFeature;
439441
}
440442
else if (typeof(TFeature) == typeof(IHttpUpgradeFeature))
441443
{
442-
feature = (TFeature)_currentIHttpUpgradeFeature;
444+
feature = (TFeature?)_currentIHttpUpgradeFeature;
443445
}
444446
else if (typeof(TFeature) == typeof(IHttp2StreamIdFeature))
445447
{
446-
feature = (TFeature)_currentIHttp2StreamIdFeature;
448+
feature = (TFeature?)_currentIHttp2StreamIdFeature;
447449
}
448450
else if (typeof(TFeature) == typeof(IHttpResponseTrailersFeature))
449451
{
450-
feature = (TFeature)_currentIHttpResponseTrailersFeature;
452+
feature = (TFeature?)_currentIHttpResponseTrailersFeature;
451453
}
452454
else if (typeof(TFeature) == typeof(IResponseCookiesFeature))
453455
{
454-
feature = (TFeature)_currentIResponseCookiesFeature;
456+
feature = (TFeature?)_currentIResponseCookiesFeature;
455457
}
456458
else if (typeof(TFeature) == typeof(IItemsFeature))
457459
{
458-
feature = (TFeature)_currentIItemsFeature;
460+
feature = (TFeature?)_currentIItemsFeature;
459461
}
460462
else if (typeof(TFeature) == typeof(ITlsConnectionFeature))
461463
{
462-
feature = (TFeature)_currentITlsConnectionFeature;
464+
feature = (TFeature?)_currentITlsConnectionFeature;
463465
}
464466
else if (typeof(TFeature) == typeof(IHttpWebSocketFeature))
465467
{
466-
feature = (TFeature)_currentIHttpWebSocketFeature;
468+
feature = (TFeature?)_currentIHttpWebSocketFeature;
467469
}
468470
else if (typeof(TFeature) == typeof(ISessionFeature))
469471
{
470-
feature = (TFeature)_currentISessionFeature;
472+
feature = (TFeature?)_currentISessionFeature;
471473
}
472474
else if (typeof(TFeature) == typeof(IHttpMaxRequestBodySizeFeature))
473475
{
474-
feature = (TFeature)_currentIHttpMaxRequestBodySizeFeature;
476+
feature = (TFeature?)_currentIHttpMaxRequestBodySizeFeature;
475477
}
476478
else if (typeof(TFeature) == typeof(IHttpMinRequestBodyDataRateFeature))
477479
{
478-
feature = (TFeature)_currentIHttpMinRequestBodyDataRateFeature;
480+
feature = (TFeature?)_currentIHttpMinRequestBodyDataRateFeature;
479481
}
480482
else if (typeof(TFeature) == typeof(IHttpMinResponseDataRateFeature))
481483
{
482-
feature = (TFeature)_currentIHttpMinResponseDataRateFeature;
484+
feature = (TFeature?)_currentIHttpMinResponseDataRateFeature;
483485
}
484486
else if (typeof(TFeature) == typeof(IHttpBodyControlFeature))
485487
{
486-
feature = (TFeature)_currentIHttpBodyControlFeature;
488+
feature = (TFeature?)_currentIHttpBodyControlFeature;
487489
}
488490
else if (typeof(TFeature) == typeof(IHttpResetFeature))
489491
{
490-
feature = (TFeature)_currentIHttpResetFeature;
492+
feature = (TFeature?)_currentIHttpResetFeature;
491493
}
492494
else if (MaybeExtra != null)
493495
{
494-
feature = (TFeature)(ExtraFeatureGet(typeof(TFeature)));
496+
feature = (TFeature?)(ExtraFeatureGet(typeof(TFeature)));
495497
}
496498

497499
if (feature == null)
@@ -619,7 +621,7 @@ void IFeatureCollection.Set<TFeature>(TFeature feature)
619621
}
620622
else
621623
{
622-
ExtraFeatureSet(typeof(TFeature), feature);
624+
ExtraFeatureSet(typeof(TFeature), feature!); // TODO: What happens if you set an extra feature with a null value?
623625
}
624626
}
625627

src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestHeaders.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private void AppendContentLength(ReadOnlySpan<byte> value)
9696
}
9797

9898
[MethodImpl(MethodImplOptions.NoInlining)]
99-
private void AppendContentLengthCustomEncoding(ReadOnlySpan<byte> value, Encoding customEncoding)
99+
private void AppendContentLengthCustomEncoding(ReadOnlySpan<byte> value, Encoding? customEncoding)
100100
{
101101
if (_contentLength.HasValue)
102102
{
@@ -105,7 +105,7 @@ private void AppendContentLengthCustomEncoding(ReadOnlySpan<byte> value, Encodin
105105

106106
// long.MaxValue = 9223372036854775807 (19 chars)
107107
Span<char> decodedChars = stackalloc char[20];
108-
var numChars = customEncoding.GetChars(value, decodedChars);
108+
var numChars = customEncoding!.GetChars(value, decodedChars);
109109
long parsed = -1;
110110

111111
if (numChars > 19 ||

src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.Generated.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
using System;
55

6+
#nullable enable
7+
68
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http2
79
{
810
internal partial class Http2Connection

src/Servers/Kestrel/Core/src/Internal/Infrastructure/HttpUtilities.Generated.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
using Microsoft.AspNetCore.Http;
77
using Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http;
88

9+
#nullable enable
10+
911
namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure
1012
{
1113
internal static partial class HttpUtilities
@@ -70,4 +72,4 @@ private static int GetKnownMethodIndex(ulong value)
7072
return ((tmp >> 2) | (tmp >> 23)) & 0xF;
7173
}
7274
}
73-
}
75+
}

0 commit comments

Comments
 (0)