Fix S1450 FP when field is assigned value in event handler #8239
Labels
Area: C#
C# rules related issues.
Sprint: Hardening
Fix FPs/FNs/improvements
Type: False Positive
Rule IS triggered when it shouldn't be.
Milestone
Description
When the value of a field is only changed in an event handler, then S1450 will be reported even though the field is used in different methods.
Repro steps
Compile the following code:
Expected behavior
S1450 is not reported.
Actual behavior
error S1450: Remove the field '_received' and declare it as a local variable in the relevant methods. (https://rules.sonarsource.com/csharp/RSPEC-1450)
If you run the compiled assembly, you'll see that "OK" is written to standard output hereby showing that the value of the _received field changed (by the event handler) between the moment it was assigned the value false and the moment we checked whether it was true.
Known workarounds
Disable the rule for the '_received' field.
Related information
The text was updated successfully, but these errors were encountered: