- Operating system: Windows 10
- SonarLint plugin version: 7.3.0.777872
- Programming language you’re coding in: VB, Visual Studio 2022
- Is connected mode used: No
I recently started getting S2589 warnings.
To prevent multiple events from being processed I use the following code. Because blnInEvent is static it is not False
Static blnInEvent As Boolean
If **blnInEvent** Then Return
blnInEvent = True
' Do Something Here
Application.DoEvents()
blnInEvent = False
Another S2589 is reported for this code where there is a potential for "objNode" to be null or nothing.
objNode = tvwShortcuts.SelectedNode
If **objNode Is Nothing** Then
Do Something Here
End If
Hello @David_Hitchner,
In this reproducer where Static blnInEvent As Boolean
is declared as such, it ends up getting the default boolean value false
and the rule is raised because If blnInEvent
will always be false.
In this particular case, the issue is a True Positive.
I could not manage to repro the second issue for the second condition with the object.
Could you please provide a more accurate reproducer that is closer to the code where the issues are raised?
Thanks!
If I understand correctly, this is multi-threading code, and S2589 is raising unexpectedly. S2589 is unaware of any multi-threading and thus is expected to create false positives for this reason.
We have some checks in place to not raise S2589 (and S2583 for this matter) if it is evident that the user is operating in a multi-threading environment. But it seems like, unfortunately, your code did not match any of the checks. If you could share more of your code, we can see if there is a good way to improve our logic to include your case.
1 Like