I use SonarQube™ Developer Edition Version 9.8 (build 63668)
Using C# and VB, we have a 20% of the rule S2259 rising false positive.
Our coding rules encourage the use of operator “?” to test pointer.
For instance in VB, the following code:
Public Sub CloseWindows(window As RadWindow)
If window?.IsOpen Then
window.Close()
End If
End Sub
will result with a new issue:
‘window’ is Nothing on at least one execution path.
or if window is null then window?.IsOpen
will return false hence the code is OK.
Is this issues has been fixed in a recent version ?
Is there a way to fix this without changing the coding rules.
The following code will resolve the issue but it do not match our coding rules.
Public Sub CloseWindows(window As RadWindow)
If window IsNot Nothing AndAlso window.IsOpen Then
window.Close()
End If
End Sub