Skip to content

Commit c31b8e2

Browse files
committed
chore(quality): remove dead null-checks flagged by CA1508
- Drop dead `?.` and `!= null` guards in 10 files where the analyzer proves the value is non-null (DI-injected helpers, catch parameters, values guaranteed by preceding null-checks). - ViteProxyHelpers.cs: suppress CA1508 with `#pragma warning disable` on the inner check of a double-checked locking pattern. The outer guard may have raced; CA1508's dataflow analysis doesn't model thread interleaving, so this is a known false positive.
1 parent bbca09c commit c31b8e2

11 files changed

Lines changed: 18 additions & 13 deletions

File tree

test/CTS/AssessmentControllerTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ private static bool IsForbidResult<T>(ActionResult<T> a)
258258
var forbidResult = a.Result as ForbidResult;
259259
if (result != null)
260260
{
261-
Assert.Equal((int)HttpStatusCode.Forbidden, result?.StatusCode);
261+
Assert.Equal((int)HttpStatusCode.Forbidden, result.StatusCode);
262262
}
263263
Assert.True(result != null || forbidResult != null);
264264

web/Areas/CTS/Controllers/AssessmentController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ public async Task<ActionResult<CreateUpdateStudentEpa>> CreateStudentEpa(CreateU
296296
.Include(p => p.StudentInfo)
297297
.Where(p => p.PersonId == epaData.StudentId)
298298
.FirstOrDefaultAsync();
299-
if (student == null || student?.StudentInfo?.ClassLevel == null)
299+
if (student == null || student.StudentInfo?.ClassLevel == null)
300300
{
301301
return BadRequest("Student not found");
302302
}

web/Areas/CTS/Controllers/CompetencyController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public async Task<ActionResult<CompetencyDto>> UpdateComptency(int competencyId,
136136
return NotFound();
137137
}
138138

139-
if (competency.CompetencyId == null || competency.CompetencyId <= 0)
139+
if (competency.CompetencyId <= 0)
140140
{
141141
return BadRequest("CompetencyId is required.");
142142
}

web/Areas/CTS/Controllers/CourseController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ private async Task<List<int>> GetCourseIdsForUserForTerm(string termCode)
490490
.ToListAsync();
491491
}
492492

493-
return context.GetMyCourses(termCode, Int32.Parse(userHelper?.GetCurrentUser()?.Pidm ?? "0"))
493+
return context.GetMyCourses(termCode, Int32.Parse(userHelper.GetCurrentUser()?.Pidm ?? "0"))
494494
.Select(c => c.CourseId)
495495
.ToList();
496496
}

web/Areas/CTS/Models/StudentEpaAssessment.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public StudentEpaAssessment(Encounter encounter) : base(encounter, encounter.Lev
2929
if (encounter.Service != null)
3030
{
3131
ServiceId = encounter.ServiceId;
32-
ServiceName = encounter.Service?.ServiceName;
32+
ServiceName = encounter.Service.ServiceName;
3333
}
3434
}
3535
}

web/Areas/Effort/Services/EvaluationReportService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ AND quant_mean > 0
283283
await using var command = new SqlCommand(sql, connection);
284284
command.Parameters.AddWithValue("@TermCode", termCode);
285285
command.Parameters.AddWithValue("@Department", (object?)department ?? DBNull.Value);
286-
command.Parameters.AddWithValue("@PersonId", (object?)personId ?? DBNull.Value);
287-
command.Parameters.AddWithValue("@Role", (object?)ParseRoleFilter(role) ?? DBNull.Value);
286+
command.Parameters.AddWithValue("@PersonId", personId);
287+
command.Parameters.AddWithValue("@Role", ParseRoleFilter(role));
288288

289289
await using var reader = await command.ExecuteReaderAsync(ct);
290290
while (await reader.ReadAsync(ct))

web/Areas/Effort/Services/MeritReportService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private async Task<List<MeritDetailRow>> ExecuteMeritReportSpAsync(
271271

272272
await using var command = new SqlCommand("[effort].[sp_merit_report]", connection);
273273
command.CommandType = CommandType.StoredProcedure;
274-
command.Parameters.AddWithValue("@PersonId", (object?)personId ?? DBNull.Value);
274+
command.Parameters.AddWithValue("@PersonId", personId);
275275
command.Parameters.AddWithValue("@StartTermCode", startTermCode);
276276
command.Parameters.AddWithValue("@EndTermCode", endTermCode);
277277
command.Parameters.AddWithValue("@Department", (object?)department ?? DBNull.Value);

web/Areas/RAPS/Services/VMACSExport.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ public async Task<List<string>> ExportToVMACS(string instance, string? server =
136136
catch (Exception ex)
137137
{
138138
HttpHelper.Logger.Log(LogLevel.Warn, ex);
139-
RecordMessage(messages, "Error: " + ex.Message + " " + ex?.StackTrace);
140-
if (ex?.InnerException != null)
139+
RecordMessage(messages, "Error: " + ex.Message + " " + ex.StackTrace);
140+
if (ex.InnerException != null)
141141
{
142-
RecordMessage(messages, "Error: " + ex.InnerException.Message + " " + ex.InnerException?.StackTrace);
142+
RecordMessage(messages, "Error: " + ex.InnerException.Message + " " + ex.InnerException.StackTrace);
143143
}
144144
}
145145
}

web/Controllers/HomeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public IActionResult EmulateUser(string loginId)
148148

149149
if (protector != null && emulatedUser.LoginId != null)
150150
{
151-
string? encryptedEmulatedLoginId = protector?.Protect(emulatedUser.LoginId);
151+
string? encryptedEmulatedLoginId = protector.Protect(emulatedUser.LoginId);
152152

153153
// set emulating cached item to expire after 30 minutes of inactivity
154154
HttpHelper.Cache?.Set(ClaimsTransformer.EmulationCacheNamePrefix + trueLoginId, encryptedEmulatedLoginId, (new MemoryCacheEntryOptions().SetSlidingExpiration(TimeSpan.FromMinutes(30))));

web/Views/Shared/Components/SessionTimeout/SessionTimeout.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public SessionTimeout()
1313
public async Task<IViewComponentResult> InvokeAsync()
1414
{
1515
UserHelper userHelper = new UserHelper();
16-
string? loginId = userHelper?.GetCurrentUser()?.LoginId;
16+
string? loginId = userHelper.GetCurrentUser()?.LoginId;
1717
bool onDev = HttpHelper.Environment?.EnvironmentName == "Development";
1818
ViewData["sessionRefreshUrl"] = (onDev ? "http://localhost/" : ("https://" + HttpHelper.HttpContext?.Request.Host.Value + "/"))
1919
+ "/public/timeout/seconds_until_timeout_v2.cfm?id="

0 commit comments

Comments
 (0)