vbnet:S2259 - var is Nothing on at least one execution path

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

Hi,

Welcome to the community!

Your version is past EOL. You should upgrade to either the latest version or the current LTS at your earliest convenience. Your upgrade path is:

9.8 → 9.9.3 → 10.3 (last step optional)

You may find these resources helpful:

If you have questions about upgrading, feel free to open a new thread for that here.

Once you’ve upgraded, can you see if this is still replicable, please?

 
Thx,
Ann