Visual Studio 17.2
SonarQube does not seem to recognise that an NUnit assertion has already validated a value is not null:
HttpResponse response = someObject As HttpResponse;
Given that the first Assert Is.Not.Null ensures the value cannot be null, S2259 should not bedetected in the second assert since it is not possible to reach that line in any execution path
similar problem if I do:
if (response == null) Assert.Fail("Response is null");
Again, there is no way to get to the second line after the previous assertion
Indeed this is a false positive.
There’s already an open issue in our repository for this.
I’m aware that the issue has been open for quite some time, but given that this rule is currently getting migrated to a new symbolic execution engine, it should be tackled in the near future.
Good to know, thanks @Mary_Georgiou
Do you have any sort of timescales on this?
I’m sorry but we don’t have an ETA currently for this.
I suggest you follow the GitHub issue for any updates.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.