Describe the bug
System.IO.FileSystemInfo.ResolveLinkTarget returns null when the directory is not a link.
IFileSystemInfo.ResolveLinkTarget ends up crashing with a null reference exception.
ResolveLinkTarget implementation in DirectoryInfoWrapper.cs
publicoverrideIFileSystemInfoResolveLinkTarget(boolreturnFinalTarget){returninstance.ResolveLinkTarget(returnFinalTarget).WrapFileSystemInfo(FileSystem);}WrapFileSystemInfo implementation in Converters.cs
privatestaticFileSystemInfoBaseWrapFileSystemInfo(IFileSystemfileSystem,FileSystemInfoitem){if(itemisFileInfofileInfo){returnWrapFileInfo(fileSystem,fileInfo);}elseif(itemisDirectoryInfodirectoryInfo){returnWrapDirectoryInfo(fileSystem,directoryInfo);}else{thrownewNotImplementedException(string.Format(CultureInfo.InvariantCulture,"The type {0} is not recognized by the System.IO.Abstractions library.",item.GetType().AssemblyQualifiedName));}}The null reference we end up hitting is because item is null in WrapFileSystemInfo.
System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=System.Private.CoreLib
StackTrace:
at System.Object.GetType()
at System.IO.Abstractions.Converters.WrapFileSystemInfo(IFileSystem fileSystem, FileSystemInfo item) in /home/runner/work/System.IO.Abstractions/System.IO.Abstractions/src/TestableIO.System.IO.Abstractions.Wrappers/Converters.cs:line 42
To Reproduce
IFileSystemfs=newFileSystem();IDirectoryInfodirinfo=fs.Directory.CreateDirectory(@"C:\Some\Dir");IFileSystemInfo?target=dirinfo.ResolveLinkTarget(true);//Crash
Expected behavior
ResolveLinkTarget should propagate the null return of the underlying System.IO API one way or another.
That API could do it directly, though it seems like WrapFileSystemInfo really ought to do the propagation itself.
Fix option 1:
privatestaticFileSystemInfoBaseWrapFileSystemInfo(IFileSystemfileSystem,FileSystemInfoitem){if(item==null){returnnull;}
...}Fix option 2:
publicoverrideIFileSystemInfoResolveLinkTarget(boolreturnFinalTarget){returninstance.ResolveLinkTarget(returnFinalTarget)?.WrapFileSystemInfo(FileSystem);}
Describe the bug
System.IO.FileSystemInfo.ResolveLinkTarget returns null when the directory is not a link.
IFileSystemInfo.ResolveLinkTarget ends up crashing with a null reference exception.
ResolveLinkTarget implementation in DirectoryInfoWrapper.cs
WrapFileSystemInfo implementation in Converters.cs
The null reference we end up hitting is because
itemis null in WrapFileSystemInfo.To Reproduce
Expected behavior
ResolveLinkTarget should propagate the null return of the underlying System.IO API one way or another.
That API could do it directly, though it seems like WrapFileSystemInfo really ought to do the propagation itself.
Fix option 1:
Fix option 2: