fix: resolve 5 SonarQube S2589 issues and improve null handling - #6734
Open
sonarqube-agent[bot] wants to merge 1 commit into
Open
fix: resolve 5 SonarQube S2589 issues and improve null handling#6734sonarqube-agent[bot] wants to merge 1 commit into
sonarqube-agent[bot] wants to merge 1 commit into
Conversation
Fixed issues: - AYd0bCS5v57I2g8Ku7Bs for csharpsquid:S1168 rule - AYqIsHySRlgCy-_ohqpH for csharpsquid:S2589 rule - AYqIsHeLRlgCy-_ohqo5 for csharpsquid:S2589 rule - AYqIsIdSRlgCy-_ohqpO for csharpsquid:S2589 rule - AZg9AzCTWEH-9cLZsOXH for csharpsquid:S2589 rule Generated by SonarQube Agent (task: 6ebc1122-c49b-4a70-af55-64274ac8532b)
nquinquenel
requested review from
kirill-knize-sonarsource
and removed request for
nquinquenel
June 11, 2026 14:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed redundant null checks and boolean conditions flagged by SonarQube static analysis across multiple files. These changes remove gratuitous pattern matches and null-conditional operators that were guaranteed to evaluate to true or false, improving code clarity and eliminating false-positive static analysis warnings.
View Project in SonarCloud
Fixed Issues
csharpsquid:S2589 - Change this condition so that it does not always evaluate to 'True'. • MAJOR • View issue
Location:
src/ConnectedMode/Persistence/SolutionBindingRepository.cs:50Why is this an issue?
Control flow constructs like
if-statements allow the programmer to direct the flow of a program depending on a boolean expression. However, if the condition is always true or always false, only one of the branches will ever be executed. In that case, the control flow construct and the condition no longer serve a purpose; they become gratuitous.What changed
The original code used 'not null' as a pattern match arm, but at that point in the control flow, the value being matched was guaranteed to be non-null (likely because a previous arm already handled the null case). This meant the 'not null' condition always evaluated to true, triggering the static analysis warning about a gratuitous boolean expression. By changing 'not null' to the discard pattern '_', the code uses a catch-all default arm instead of a redundant non-null check, eliminating the always-true condition while preserving the same runtime behavior.
csharpsquid:S2589 - Remove this unnecessary check for null. • MAJOR • View issue
Location:
src/ConnectedMode/Migration/RoslynProjectProvider.cs:61Why is this an issue?
Control flow constructs like
if-statements allow the programmer to direct the flow of a program depending on a boolean expression. However, if the condition is always true or always false, only one of the branches will ever be executed. In that case, the control flow construct and the condition no longer serve a purpose; they become gratuitous.What changed
This hunk removes the null-conditional operators (?.) from
wrappedWorkspace?.CurrentSolution?.and replaces them with direct member access (wrappedWorkspace.CurrentSolution.). The static analysis determined thatwrappedWorkspaceis never null at this point in the code, making the null-conditional checks gratuitous. By removing the unnecessary null checks, the code no longer triggers the 'Remove this unnecessary check for null' warning (rule S2589) and becomes clearer about its actual intent.csharpsquid:S1168 - Return an empty collection instead of null. • MAJOR • View issue
Location:
src/IssueViz/IssueVisualizationControl/ViewModels/Commands/NavigateToRuleDescriptionCommand.cs:86Why is this an issue?
Returning
nullordefaultinstead of an actual collection forces the method callers to explicitly test for null, making the code more complex and less readable.What changed
This hunk replaces
return null;withreturn Array.Empty<object>();in theNavigateToRuleDescriptionCommandConverterclass. The static analysis rule flags returning null from a method that returns a collection type, since it forces callers to check for null and is less readable. By returning an empty array instead of null, the code follows the best practice of returning an empty collection, which eliminates the need for null checks by callers.csharpsquid:S2589 - Change this condition so that it does not always evaluate to 'False'. • MAJOR • View issue
Location:
src/Integration/Helpers/OutputWindowService.cs:50Why is this an issue?
Control flow constructs like
if-statements allow the programmer to direct the flow of a program depending on a boolean expression. However, if the condition is always true or always false, only one of the branches will ever be executed. In that case, the control flow construct and the condition no longer serve a purpose; they become gratuitous.What changed
Removes the
Debug.Assert(sonarLintOutputPane != null, ...)line that follows a code path wheresonarLintOutputPaneis guaranteed to be non-null (since the null case was already handled earlier). The static analyzer flagged thesonarLintOutputPane == nullcondition within this assert as always evaluating to 'False', making it a gratuitous boolean expression. By removing the entireDebug.Assertstatement, the always-false condition is eliminated.csharpsquid:S2589 - Change this condition so that it does not always evaluate to 'False'. • MAJOR • View issue
Location:
src/Core/FileMonitor/SingleFileMonitor.cs:139Why is this an issue?
Control flow constructs like
if-statements allow the programmer to direct the flow of a program depending on a boolean expression. However, if the condition is always true or always false, only one of the branches will ever be executed. In that case, the control flow construct and the condition no longer serve a purpose; they become gratuitous.What changed
This hunk removes the
Debug.Assertline that contained the conditionfileChangedHandlers == null || disposedValuwhich was flagged as always evaluating to 'False'. SincefileChangedHandlersis never null at that point in the code flow, the null check portion of the condition is gratuitous. By removing the entire assertion line, the always-false condition is eliminated, resolving the code smell about a boolean expression that never changes the evaluation result.SonarQube Remediation Agent uses AI. Check for mistakes.