Skip to content

Commit 64a2681

Browse files
Remove null markers to avoid NullReferenceException (#1907)
1 parent ba293c9 commit 64a2681

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/PowerShellEditorServices/Services/Analysis/AnalysisService.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public async Task<IReadOnlyDictionary<string, IEnumerable<MarkerCorrection>>> Ge
235235
/// </summary>
236236
/// <param name="file">The file to clear markers in.</param>
237237
/// <returns>A task that ends when all markers in the file have been cleared.</returns>
238-
public void ClearMarkers(ScriptFile file) => PublishScriptDiagnostics(file, Array.Empty<ScriptFileMarker>());
238+
public void ClearMarkers(ScriptFile file) => PublishScriptDiagnostics(file, new List<ScriptFileMarker>());
239239

240240
/// <summary>
241241
/// Event subscription method to be run when PSES configuration has been updated.
@@ -384,8 +384,11 @@ internal async Task DelayThenInvokeDiagnosticsAsync(ScriptFile[] filesToAnalyze,
384384

385385
private void PublishScriptDiagnostics(ScriptFile scriptFile) => PublishScriptDiagnostics(scriptFile, scriptFile.DiagnosticMarkers);
386386

387-
private void PublishScriptDiagnostics(ScriptFile scriptFile, IReadOnlyList<ScriptFileMarker> markers)
387+
private void PublishScriptDiagnostics(ScriptFile scriptFile, List<ScriptFileMarker> markers)
388388
{
389+
// NOTE: Sometimes we have null markers for reasons we don't yet know, but we need to
390+
// remove them.
391+
_ = markers.RemoveAll(m => m is null);
389392
Diagnostic[] diagnostics = new Diagnostic[markers.Count];
390393

391394
CorrectionTableEntry fileCorrections = _mostRecentCorrectionsByFile.GetOrAdd(

0 commit comments

Comments
 (0)