Reporter | Alexander Kurakin (Alexander.Kurakin) |
---|---|
Created | Mar 6, 2017 3:28:14 PM |
Updated | Apr 15, 2018 3:41:40 AM |
Subsystem | Code Analysis - Annotations |
Assignee | Alexander Shvedov (shvedov) |
Priority | Major |
State | Submitted |
Type | Bug |
Fix version | 2017.2 |
Affected versions | 2017.1 |
Fixed In Version ReSharper | Undefined |
VsVersion | All Versions |
The code below has ReSharper mistakenly complaining that the results of server.MapPath() can be null, and that therefore File.GetLastWriteTime() is potentially being given a null argument.
If you pass a null to MapPath, ReSharper is (correctly) happy that this result can be passed successfully to GetLastWriteTime() – there is a guaranteed non-null result from GetLastWriteTime(null). If you pass a NON-null argument to MapPath(), ReSharper is also (correctly) happy. It is only if you pass a variable like "file" to the MapPath() method that ReSharper (incorrectly) complains.
If you pass a null to MapPath, ReSharper is (correctly) happy that this result can be passed successfully to GetLastWriteTime() – there is a guaranteed non-null result from GetLastWriteTime(null). If you pass a NON-null argument to MapPath(), ReSharper is also (correctly) happy. It is only if you pass a variable like "file" to the MapPath() method that ReSharper (incorrectly) complains.
private DateTime NullParameterIssue( [NotNull] System.Web.HttpServerUtility server,
[CanBeNull] string file)
=> System.IO.File.GetLastWriteTime(server.MapPath(file));