Skip to content

Remove null markers to avoid NullReferenceException #1907

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public async Task<IReadOnlyDictionary<string, IEnumerable<MarkerCorrection>>> Ge
/// </summary>
/// <param name="file">The file to clear markers in.</param>
/// <returns>A task that ends when all markers in the file have been cleared.</returns>
public void ClearMarkers(ScriptFile file) => PublishScriptDiagnostics(file, Array.Empty<ScriptFileMarker>());
public void ClearMarkers(ScriptFile file) => PublishScriptDiagnostics(file, new List<ScriptFileMarker>());

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

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

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

CorrectionTableEntry fileCorrections = _mostRecentCorrectionsByFile.GetOrAdd(
Expand Down