|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: "Nikola Milosavljevic (CLR) false" < [email protected]> |
| 3 | +Date: Mon, 7 Apr 2025 19:28:29 -0700 |
| 4 | +Subject: [PATCH] IDE0031 fixes |
| 5 | + |
| 6 | +Backport: https://github.com/dotnet/aspnetcore/pull/61244 |
| 7 | +--- |
| 8 | + src/Components/Server/src/Circuits/CircuitHost.cs | 5 +---- |
| 9 | + .../Hosting/src/Http/DefaultHttpContextFactory.cs | 15 +++------------ |
| 10 | + src/Http/Http/src/HttpContextAccessor.cs | 8 ++------ |
| 11 | + src/Middleware/Rewrite/src/RewriteMiddleware.cs | 6 +----- |
| 12 | + .../src/UrlActions/CustomResponseAction.cs | 7 ++----- |
| 13 | + .../StaticFiles/src/StaticFileContext.cs | 6 +----- |
| 14 | + .../ModelBinding/Validation/ValidationVisitor.cs | 7 +------ |
| 15 | + .../src/Filters/SaveTempDataFilter.cs | 13 ++----------- |
| 16 | + .../src/SkipStatusCodePagesAttribute.cs | 8 ++------ |
| 17 | + .../Negotiate/src/NegotiateHandler.cs | 5 +---- |
| 18 | + .../HttpSys/src/RequestProcessing/Request.cs | 5 +---- |
| 19 | + .../HttpSys/src/RequestProcessing/Response.cs | 5 +---- |
| 20 | + src/Shared/HttpExtensions.cs | 6 +----- |
| 21 | + .../dotnet-user-jwts/src/Helpers/JwtStore.cs | 5 +---- |
| 22 | + 14 files changed, 20 insertions(+), 81 deletions(-) |
| 23 | + |
| 24 | +diff --git a/src/Components/Server/src/Circuits/CircuitHost.cs b/src/Components/Server/src/Circuits/CircuitHost.cs |
| 25 | +index 66c636ba01..3a9bea6bd8 100644 |
| 26 | +--- a/src/Components/Server/src/Circuits/CircuitHost.cs |
| 27 | ++++ b/src/Components/Server/src/Circuits/CircuitHost.cs |
| 28 | +@@ -828,10 +828,7 @@ internal partial class CircuitHost : IAsyncDisposable |
| 29 | + operation.Descriptor.ComponentType, |
| 30 | + operation.Marker.Value.Key, |
| 31 | + operation.Descriptor.Parameters); |
| 32 | +- if (pendingTasks != null) |
| 33 | +- { |
| 34 | +- pendingTasks[i] = task; |
| 35 | +- } |
| 36 | ++ pendingTasks?[i] = task; |
| 37 | + break; |
| 38 | + case RootComponentOperationType.Update: |
| 39 | + // We don't need to await component updates as any unhandled exception will be reported and terminate the circuit. |
| 40 | +diff --git a/src/Hosting/Hosting/src/Http/DefaultHttpContextFactory.cs b/src/Hosting/Hosting/src/Http/DefaultHttpContextFactory.cs |
| 41 | +index a5b6541b0f..d087dc54d9 100644 |
| 42 | +--- a/src/Hosting/Hosting/src/Http/DefaultHttpContextFactory.cs |
| 43 | ++++ b/src/Hosting/Hosting/src/Http/DefaultHttpContextFactory.cs |
| 44 | +@@ -58,10 +58,7 @@ public class DefaultHttpContextFactory : IHttpContextFactory |
| 45 | + |
| 46 | + httpContext.Initialize(featureCollection); |
| 47 | + |
| 48 | +- if (_httpContextAccessor != null) |
| 49 | +- { |
| 50 | +- _httpContextAccessor.HttpContext = httpContext; |
| 51 | +- } |
| 52 | ++ _httpContextAccessor?.HttpContext = httpContext; |
| 53 | + |
| 54 | + httpContext.FormOptions = _formOptions; |
| 55 | + httpContext.ServiceScopeFactory = _serviceScopeFactory; |
| 56 | +@@ -72,18 +69,12 @@ public class DefaultHttpContextFactory : IHttpContextFactory |
| 57 | + /// </summary> |
| 58 | + public void Dispose(HttpContext httpContext) |
| 59 | + { |
| 60 | +- if (_httpContextAccessor != null) |
| 61 | +- { |
| 62 | +- _httpContextAccessor.HttpContext = null; |
| 63 | +- } |
| 64 | ++ _httpContextAccessor?.HttpContext = null; |
| 65 | + } |
| 66 | + |
| 67 | + internal void Dispose(DefaultHttpContext httpContext) |
| 68 | + { |
| 69 | +- if (_httpContextAccessor != null) |
| 70 | +- { |
| 71 | +- _httpContextAccessor.HttpContext = null; |
| 72 | +- } |
| 73 | ++ _httpContextAccessor?.HttpContext = null; |
| 74 | + |
| 75 | + httpContext.Uninitialize(); |
| 76 | + } |
| 77 | +diff --git a/src/Http/Http/src/HttpContextAccessor.cs b/src/Http/Http/src/HttpContextAccessor.cs |
| 78 | +index f71a6ef7c0..d306a8dbeb 100644 |
| 79 | +--- a/src/Http/Http/src/HttpContextAccessor.cs |
| 80 | ++++ b/src/Http/Http/src/HttpContextAccessor.cs |
| 81 | +@@ -22,12 +22,8 @@ public class HttpContextAccessor : IHttpContextAccessor |
| 82 | + } |
| 83 | + set |
| 84 | + { |
| 85 | +- var holder = _httpContextCurrent.Value; |
| 86 | +- if (holder != null) |
| 87 | +- { |
| 88 | +- // Clear current HttpContext trapped in the AsyncLocals, as its done. |
| 89 | +- holder.Context = null; |
| 90 | +- } |
| 91 | ++ // Clear current HttpContext trapped in the AsyncLocals, as its done. |
| 92 | ++ _httpContextCurrent.Value?.Context = null; |
| 93 | + |
| 94 | + if (value != null) |
| 95 | + { |
| 96 | +diff --git a/src/Middleware/Rewrite/src/RewriteMiddleware.cs b/src/Middleware/Rewrite/src/RewriteMiddleware.cs |
| 97 | +index d76ea33d21..7dcd2ca11b 100644 |
| 98 | +--- a/src/Middleware/Rewrite/src/RewriteMiddleware.cs |
| 99 | ++++ b/src/Middleware/Rewrite/src/RewriteMiddleware.cs |
| 100 | +@@ -77,11 +77,7 @@ public class RewriteMiddleware |
| 101 | + // An endpoint may have already been set. Since we're going to re-invoke the middleware pipeline we need to reset |
| 102 | + // the endpoint and route values to ensure things are re-calculated. |
| 103 | + context.SetEndpoint(endpoint: null); |
| 104 | +- var routeValuesFeature = context.Features.Get<IRouteValuesFeature>(); |
| 105 | +- if (routeValuesFeature is not null) |
| 106 | +- { |
| 107 | +- routeValuesFeature.RouteValues = null!; |
| 108 | +- } |
| 109 | ++ context.Features.Get<IRouteValuesFeature>()?.RouteValues = null!; |
| 110 | + return _options.BranchedNext(context); |
| 111 | + } |
| 112 | + } |
| 113 | +diff --git a/src/Middleware/Rewrite/src/UrlActions/CustomResponseAction.cs b/src/Middleware/Rewrite/src/UrlActions/CustomResponseAction.cs |
| 114 | +index 4c29d034ae..3954db7a70 100644 |
| 115 | +--- a/src/Middleware/Rewrite/src/UrlActions/CustomResponseAction.cs |
| 116 | ++++ b/src/Middleware/Rewrite/src/UrlActions/CustomResponseAction.cs |
| 117 | +@@ -31,11 +31,8 @@ internal sealed class CustomResponseAction : UrlAction |
| 118 | + |
| 119 | + if (!string.IsNullOrEmpty(StatusDescription)) |
| 120 | + { |
| 121 | +- var feature = context.HttpContext.Features.Get<IHttpBodyControlFeature>(); |
| 122 | +- if (feature != null) |
| 123 | +- { |
| 124 | +- feature.AllowSynchronousIO = true; |
| 125 | +- } |
| 126 | ++ context.HttpContext.Features.Get<IHttpBodyControlFeature>()?.AllowSynchronousIO = true; |
| 127 | ++ |
| 128 | + var content = Encoding.UTF8.GetBytes(StatusDescription); |
| 129 | + response.ContentLength = content.Length; |
| 130 | + response.ContentType = "text/plain; charset=utf-8"; |
| 131 | +diff --git a/src/Middleware/StaticFiles/src/StaticFileContext.cs b/src/Middleware/StaticFiles/src/StaticFileContext.cs |
| 132 | +index 69e8d8c595..48bd869249 100644 |
| 133 | +--- a/src/Middleware/StaticFiles/src/StaticFileContext.cs |
| 134 | ++++ b/src/Middleware/StaticFiles/src/StaticFileContext.cs |
| 135 | +@@ -407,11 +407,7 @@ internal struct StaticFileContext |
| 136 | + // Only called when we expect to serve the body. |
| 137 | + private void SetCompressionMode() |
| 138 | + { |
| 139 | +- var responseCompressionFeature = _context.Features.Get<IHttpsCompressionFeature>(); |
| 140 | +- if (responseCompressionFeature != null) |
| 141 | +- { |
| 142 | +- responseCompressionFeature.Mode = _options.HttpsCompression; |
| 143 | +- } |
| 144 | ++ _context.Features.Get<IHttpsCompressionFeature>()?.Mode = _options.HttpsCompression; |
| 145 | + } |
| 146 | + |
| 147 | + internal enum PreconditionState : byte |
| 148 | +diff --git a/src/Mvc/Mvc.Core/src/ModelBinding/Validation/ValidationVisitor.cs b/src/Mvc/Mvc.Core/src/ModelBinding/Validation/ValidationVisitor.cs |
| 149 | +index 68c71a5e48..48e1580609 100644 |
| 150 | +--- a/src/Mvc/Mvc.Core/src/ModelBinding/Validation/ValidationVisitor.cs |
| 151 | ++++ b/src/Mvc/Mvc.Core/src/ModelBinding/Validation/ValidationVisitor.cs |
| 152 | +@@ -248,12 +248,7 @@ public class ValidationVisitor |
| 153 | + { |
| 154 | + // If the field has an entry in ModelState, then record it as valid. Don't create |
| 155 | + // extra entries if they don't exist already. |
| 156 | +- var entry = ModelState[Key]; |
| 157 | +- if (entry != null) |
| 158 | +- { |
| 159 | +- entry.ValidationState = ModelValidationState.Valid; |
| 160 | +- } |
| 161 | +- |
| 162 | ++ ModelState[Key]?.ValidationState = ModelValidationState.Valid; |
| 163 | + return true; |
| 164 | + } |
| 165 | + } |
| 166 | +diff --git a/src/Mvc/Mvc.ViewFeatures/src/Filters/SaveTempDataFilter.cs b/src/Mvc/Mvc.ViewFeatures/src/Filters/SaveTempDataFilter.cs |
| 167 | +index 2da398ae0e..20e78949b6 100644 |
| 168 | +--- a/src/Mvc/Mvc.ViewFeatures/src/Filters/SaveTempDataFilter.cs |
| 169 | ++++ b/src/Mvc/Mvc.ViewFeatures/src/Filters/SaveTempDataFilter.cs |
| 170 | +@@ -83,11 +83,7 @@ internal sealed class SaveTempDataFilter : IResourceFilter, IResultFilter |
| 171 | + // not be available. |
| 172 | + if (!context.HttpContext.Response.HasStarted && context.Exception != null) |
| 173 | + { |
| 174 | +- var saveTempDataContext = GetTempDataContext(context.HttpContext); |
| 175 | +- if (saveTempDataContext != null) |
| 176 | +- { |
| 177 | +- saveTempDataContext.RequestHasUnhandledException = true; |
| 178 | +- } |
| 179 | ++ GetTempDataContext(context.HttpContext)?.RequestHasUnhandledException = true; |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | +@@ -105,12 +101,7 @@ internal sealed class SaveTempDataFilter : IResourceFilter, IResultFilter |
| 184 | + if (!context.HttpContext.Response.HasStarted) |
| 185 | + { |
| 186 | + SaveTempData(context.Result, _factory, context.Filters, context.HttpContext); |
| 187 | +- |
| 188 | +- var saveTempDataContext = GetTempDataContext(context.HttpContext); |
| 189 | +- if (saveTempDataContext != null) |
| 190 | +- { |
| 191 | +- saveTempDataContext.TempDataSaved = true; |
| 192 | +- } |
| 193 | ++ GetTempDataContext(context.HttpContext)?.TempDataSaved = true; |
| 194 | + } |
| 195 | + } |
| 196 | + |
| 197 | +diff --git a/src/Mvc/Mvc.ViewFeatures/src/SkipStatusCodePagesAttribute.cs b/src/Mvc/Mvc.ViewFeatures/src/SkipStatusCodePagesAttribute.cs |
| 198 | +index c0abec8fa2..ebf3a237b9 100644 |
| 199 | +--- a/src/Mvc/Mvc.ViewFeatures/src/SkipStatusCodePagesAttribute.cs |
| 200 | ++++ b/src/Mvc/Mvc.ViewFeatures/src/SkipStatusCodePagesAttribute.cs |
| 201 | +@@ -23,11 +23,7 @@ public class SkipStatusCodePagesAttribute : Attribute, IResourceFilter, ISkipSta |
| 202 | + { |
| 203 | + ArgumentNullException.ThrowIfNull(context); |
| 204 | + |
| 205 | +- var statusCodeFeature = context.HttpContext.Features.Get<IStatusCodePagesFeature>(); |
| 206 | +- if (statusCodeFeature != null) |
| 207 | +- { |
| 208 | +- // Turn off the StatusCodePages feature. |
| 209 | +- statusCodeFeature.Enabled = false; |
| 210 | +- } |
| 211 | ++ // Turn off the StatusCodePages feature. |
| 212 | ++ context.HttpContext.Features.Get<IStatusCodePagesFeature>()?.Enabled = false; |
| 213 | + } |
| 214 | + } |
| 215 | +diff --git a/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs b/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs |
| 216 | +index b1909d52cc..ace6899428 100644 |
| 217 | +--- a/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs |
| 218 | ++++ b/src/Security/Authentication/Negotiate/src/NegotiateHandler.cs |
| 219 | +@@ -126,10 +126,7 @@ public class NegotiateHandler : AuthenticationHandler<NegotiateOptions>, IAuthen |
| 220 | + Logger.Reauthenticating(); |
| 221 | + _negotiateState.Dispose(); |
| 222 | + _negotiateState = null; |
| 223 | +- if (persistence != null) |
| 224 | +- { |
| 225 | +- persistence.State = null; |
| 226 | +- } |
| 227 | ++ persistence?.State = null; |
| 228 | + } |
| 229 | + |
| 230 | + _negotiateState ??= Options.StateFactory.CreateInstance(); |
| 231 | +diff --git a/src/Servers/HttpSys/src/RequestProcessing/Request.cs b/src/Servers/HttpSys/src/RequestProcessing/Request.cs |
| 232 | +index b32a973a5f..8e4babf7ca 100644 |
| 233 | +--- a/src/Servers/HttpSys/src/RequestProcessing/Request.cs |
| 234 | ++++ b/src/Servers/HttpSys/src/RequestProcessing/Request.cs |
| 235 | +@@ -264,10 +264,7 @@ internal sealed partial class Request |
| 236 | + set |
| 237 | + { |
| 238 | + EnsureRequestStream(); |
| 239 | +- if (_nativeStream != null) |
| 240 | +- { |
| 241 | +- _nativeStream.MaxSize = value; |
| 242 | +- } |
| 243 | ++ _nativeStream?.MaxSize = value; |
| 244 | + } |
| 245 | + } |
| 246 | + |
| 247 | +diff --git a/src/Servers/HttpSys/src/RequestProcessing/Response.cs b/src/Servers/HttpSys/src/RequestProcessing/Response.cs |
| 248 | +index f2f550544e..541199729a 100644 |
| 249 | +--- a/src/Servers/HttpSys/src/RequestProcessing/Response.cs |
| 250 | ++++ b/src/Servers/HttpSys/src/RequestProcessing/Response.cs |
| 251 | +@@ -186,10 +186,7 @@ internal sealed class Response |
| 252 | + // callers if they try to add them too late. E.g. after Content-Length or CompleteAsync(). |
| 253 | + internal void MakeTrailersReadOnly() |
| 254 | + { |
| 255 | +- if (_trailers != null) |
| 256 | +- { |
| 257 | +- _trailers.IsReadOnly = true; |
| 258 | +- } |
| 259 | ++ _trailers?.IsReadOnly = true; |
| 260 | + } |
| 261 | + |
| 262 | + internal void Abort() |
| 263 | +diff --git a/src/Shared/HttpExtensions.cs b/src/Shared/HttpExtensions.cs |
| 264 | +index 4a0d50de25..3e2bde30e8 100644 |
| 265 | +--- a/src/Shared/HttpExtensions.cs |
| 266 | ++++ b/src/Shared/HttpExtensions.cs |
| 267 | +@@ -58,10 +58,6 @@ internal static class HttpExtensions |
| 268 | + context.SetEndpoint(endpoint: null); |
| 269 | + } |
| 270 | + |
| 271 | +- var routeValuesFeature = context.Features.Get<IRouteValuesFeature>(); |
| 272 | +- if (routeValuesFeature != null) |
| 273 | +- { |
| 274 | +- routeValuesFeature.RouteValues = null!; |
| 275 | +- } |
| 276 | ++ context.Features.Get<IRouteValuesFeature>()?.RouteValues = null!; |
| 277 | + } |
| 278 | + } |
| 279 | +diff --git a/src/Tools/dotnet-user-jwts/src/Helpers/JwtStore.cs b/src/Tools/dotnet-user-jwts/src/Helpers/JwtStore.cs |
| 280 | +index 79ca7f05c9..d32affe119 100644 |
| 281 | +--- a/src/Tools/dotnet-user-jwts/src/Helpers/JwtStore.cs |
| 282 | ++++ b/src/Tools/dotnet-user-jwts/src/Helpers/JwtStore.cs |
| 283 | +@@ -18,10 +18,7 @@ public class JwtStore |
| 284 | + Load(); |
| 285 | + |
| 286 | + // For testing. |
| 287 | +- if (program is not null) |
| 288 | +- { |
| 289 | +- program.UserJwtsFilePath = _filePath; |
| 290 | +- } |
| 291 | ++ program?.UserJwtsFilePath = _filePath; |
| 292 | + } |
| 293 | + |
| 294 | + public IDictionary<string, Jwt> Jwts { get; private set; } = new Dictionary<string, Jwt>(); |
0 commit comments