Quantcast
Channel: YouTrackReSharper (RSRP) - Bug and Issue Tracker
Viewing all articles
Browse latest Browse all 106942

RSRP-467104: "Possible NullReferenceException" after using null conditional operator

$
0
0
Reporter Liam Symonds (lssoftware) Liam Symonds (lssoftware)
Created Nov 19, 2017 1:33:43 AM
Updated Apr 17, 2018 10:17:00 AM
Resolved Apr 17, 2018 10:17:00 AM
Subsystem Code Analysis - C#
Assignee Ivan Serduk (IvanSerduk)
Priority Critical
State Fixed
Type Bug
Fix version 2017.3
Affected versions 2017.2
Fixed In Version ReSharper Undefined
VsVersion All Versions
Repro steps:

1) Have a class that has a string property in it (i.e. public class Foo { public string Bar { get; set; } }).
2) Create a method that has that class as a parameter (i.e. public void FooBar(Foo x)).
3) Use the null conditional operator to check whether 'Bar' is null (i.e. if (string.IsNullOrWhiteSpace(x?.Bar)).
4) Try and use the 'x' parameter (i.e. var z = x.Email;)
5) Get a 'Possible null exception alarm', even though the check would fail.

Full code example here: https://gitlab.com/snippets/1685111

Let me know if you need any other examples.

Viewing all articles
Browse latest Browse all 106942

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>