S1125 does not get fixed correctly


I have a problem how SonarLint for Visual Studio 2022 (Version running on Win 11) fixes the issue S1125 in some cases, and I haven’t found any bug reports regarding this issue:

The statement

var test = obj == null ? false : obj.ToString() == "x" || obj.ToString() == "y";

gets fixed to

var test = !(obj == null) && obj.ToString() == "x" || obj.ToString() == "y";

This will lead to a null pointer exception if obj is null, which would not happen in the original code.

Hello @Jerrod,

Thanks a lot for reporting this bug.
I’ve added an issue to our backlog to tackle in a future sprint.

You can follow it here.

Best Regards

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.