Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable annotate System.Diagnostics.Process #31671

Conversation

eiriktsarpalis
Copy link
Member

Contributes to #2339

Copy link
Contributor

@buyaa-n buyaa-n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few questions, overall LGTM

public static System.Diagnostics.Process Start(string fileName, string arguments) { throw null; }
public static System.Diagnostics.Process? Start(System.Diagnostics.ProcessStartInfo startInfo) { throw null; }
public static System.Diagnostics.Process? Start(string fileName) { throw null; }
public static System.Diagnostics.Process? Start(string fileName, string arguments) { throw null; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of those cases where the annotation is correct but it's probably going to cause more harm than good I think. Still, we should keep what you have.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the only code path that could result in a null Process value is this one. It doesn't seem possible on the unix implementation.

The particular result stems from this shell32 function. I don't understand enough about that particular API to judge the probability of this happening, but we do seem to throw beforehand if the call is not successful.

That being said, the nullity of the particular call seems to merely reflect the result of the also public bool Process.Start() instance method, so it might make sense to keep for the sake of symmetry?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible for Start to return false, if shell execute is used and returns successfully a zero handle. However, the default for ProcessStartInfo.UseShellExecute in .NET Core is false, which means while to be accurate we do need Start(ProcessStartInfo) to return Process?, the other Start(string) and Start(string, string) overloads should never return null, because they don't use shell execute, so unless I'm missing something, those should return just Process. Reasonable?

Copy link
Member Author

@eiriktsarpalis eiriktsarpalis Feb 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your analysis makes sense. One counterpoint here is that most real uses of Process.Start() I've seen typically either use ProcessStartInfo or call the Start() instance method directly. So the question here is whether we want to assert non-nullability for a special case of the api based on an invariant which may change in the future or not hold at all in future platforms.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the question here is whether we want to assert non-nullability for a special case of the api based on an invariant which may change in the future or not hold at all in future platforms.

It'd be a breaking change to start returning null in cases where we don't today, regardless of annotation, and even if documented to say null is possible. So I'm not worried about this. If we wanted to make such a breaking change, we'd break the annotation as part of it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair enough

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the outstanding comments, LGTM.

@eiriktsarpalis eiriktsarpalis force-pushed the annotate-system-diagnostics-process branch from 853675f to f2407c3 Compare February 6, 2020 12:47
@eiriktsarpalis eiriktsarpalis merged commit 90a2d87 into dotnet:master Feb 6, 2020
@eiriktsarpalis eiriktsarpalis deleted the annotate-system-diagnostics-process branch February 6, 2020 18:18
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants