Bug 58653 - NSApplication.SharedApplication.Terminate(null) throws exception
Summary: NSApplication.SharedApplication.Terminate(null) throws exception
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 3.8.0 (d15-4)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 15.4
Assignee: Bugzilla
Depends on:
Reported: 2017-08-09 00:11 UTC by William Kent
Modified: 2017-08-10 13:44 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description William Kent 2017-08-09 00:11:45 UTC
When I pass `null` as a parameter to `NSApplication.SharedApplication.Terminate()`, an ArgumentNullException is thrown. IMHO, this is undesirable behavior, as passing a `null`/`nil` sender is a common Cocoa idiom for when the sender is unimportant, and all references to it should be ignored by the callee.
Comment 1 Chris Hamons 2017-08-09 14:56:46 UTC
You are correct, the header notes the selector as:

- (void)terminate:(nullable id)sender;

To give you some backstory explaining the bug:

- Until recently, Apple's headers did _not_ note which items were nullable
- Thus, when binding one had to be careful to manually test when it was not clear
- By default we "fail safe" and assume null is an invalid value. We do this because a managed ArgumentNullException is easy to catch/debug for many, while a native crash, with walls of angry red text in the console, is not.
- We can add a [NullAllowed] to our bindings to fix this.
- Not every existing binding has been scrubbed since Apple introduced nullability markups
Comment 2 Chris Hamons 2017-08-09 14:59:04 UTC
There are 202 instances of "NSObject sender" in appkit.cs which likely contain the problem without [NullAllowed], 161 without it.
Comment 3 Chris Hamons 2017-08-09 15:00:13 UTC
Each instance will need to be checked against the headers.
Comment 4 Sebastien Pouliot 2017-08-09 16:48:06 UTC
@Chris you're right but this needs to be added to the xtro tests (it's on the TODO) and not a manual audit. There's too many API and Apple changes/update nullability too often to do this manually. Also other frameworks needs the same review.

That being said let's fix the requested API asap (for 15.4) and track the overall issue in a separate bug.
Comment 5 Chris Hamons 2017-08-09 17:11:48 UTC
Yeah, that's what I was thinking actually (I prefer not to check 160+ items by hand when I can avoid it). :)

I'll fix this single item for 15.4.
Comment 6 Chris Hamons 2017-08-09 17:23:13 UTC
https://bugzilla.xamarin.com/show_bug.cgi?id=58674 for the systemic issue
Comment 7 Chris Hamons 2017-08-09 17:26:15 UTC