S2583 false positive: complex pattern matching in C# 11

The issue is as shown in the screenshot:

if (exception is InvalidOperationException { Message: "The connection is closed." or "Invalid operation. The connection is closed." })
    return true;

if (exception is SqlException
    {
        Errors:
        [
            {
                Class: 20,
                Number: 0,
                Message: "A transport-level error has occurred when receiving results from the server. " +
                         "(provider: TCP Provider, error: 2 - Connection was terminated: Connection was terminated)"
            }
        ]
    })
    return true;

return false;

I see the issue both in SonarQube (v. 9.6.1) and in SonarLint. I have tests that hits all branches of the code.

Simplifying the pattern solves the issue.

Hi,

Welcome to the community and thanks for this report!

Does this issue look relevant? (Hard for me to tell; I’ve never done C#.)

 
Ann

That does look relevant.

Also, it seems to no longer show up in SonarLint, so maybe it has been fixed already?

Hi,

The issue is still Open, so I don’t think so. Are you running SonarLint in connected mode?

 
Ann

I am.

Right - and that means it ignores it because I ignored it on the server :person_facepalming:

Still learning how Sonar works :slight_smile:

1 Like

No worries!

So if you subscribe to notifications on that issue, you’ll be notified when it’s fixed.

And BTW, you do realize you’re not on the latest SQ version, right?

 
Ann

I’ll keep an eye on that.

We’ve upgraded the installation now, but thanks for the reminder :slight_smile:

1 Like