-
Notifications
You must be signed in to change notification settings - Fork 266
Closed
Labels
state: needs discussionIssues that need further discussionIssues that need further discussionstate: releasedIssues that are releasedIssues that are releasedtype: bugIssues that describe misbehaving functionalityIssues that describe misbehaving functionality
Description
Describe the bug
The implementations for FileInfoFactory.Wrap and DirectoryInfoFactory.Wrap require non-null references, while the interfaces are defined as [return: NotNullIfNotNull("fileInfo")] IFileInfoFactory.Wrap(FileInfo? fileInfo) and likewise for IDirectoryInfoFactory.Wrap.
To Reproduce
Steps to reproduce the behavior:
new FileSystem().FileInfo.Wrap(null);- The analyzer and compiler accept the syntax since
IFileInfoFactory.WrapacceptsFileInfo?and returnsIFileInfo? - An
ArgumentNullExceptionis thrown
Expected behavior
I expect to get a null IFileInfo? back if the input is null, and no exception thrown.
Additional context
Fixing this will help compatibility with System.CommandLine where defining options as FileInfo? is a common practice, i.e.:
var inputFileOption = new Option<FileInfo?>("--input");
var command = new Command("test") { inputFileOption };
command.SetHandler(
(FileInfo? inputFile) => {
var fileSystem = new FileSystem();
var concreteCommand = new ConcreteCommand(fileSystem:fileSystem) {
InputFile = fileSystem.FileInfo.Wrap(inputFile)
}
concreteCommand.Run();
},
inputFileOption
);Metadata
Metadata
Assignees
Labels
state: needs discussionIssues that need further discussionIssues that need further discussionstate: releasedIssues that are releasedIssues that are releasedtype: bugIssues that describe misbehaving functionalityIssues that describe misbehaving functionality