Bug 42895 - CallKit ReportNewIncomingCall completion parameter is allowed to be null
Summary: CallKit ReportNewIncomingCall completion parameter is allowed to be null
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.99 (iOS 10 previews)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Xcode8 (iOS10)
Assignee: Bugzilla
Depends on:
Reported: 2016-07-28 17:40 UTC by kkurz
Modified: 2016-08-22 13:06 UTC (History)
3 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 kkurz 2016-07-28 17:40:28 UTC
The completion Action<NSError> field of the CallKit:ReportNewIncomingCall function is allowed to be null'd by the compiler, but will crash at runtime if it's null. The compiler should enforce this to avoid confusion/developer issues.
Comment 1 Alex Soto [MSFT] 2016-07-29 21:36:28 UTC
It seems that generator does not honor the absence of NullAllowed on blocks

Comment 2 Sebastien Pouliot 2016-08-19 13:14:40 UTC
The generated code does include a null check for the `completion` parameter.

	[Export ("reportNewIncomingCallWithUUID:update:completion:")]
	public unsafe virtual void ReportNewIncomingCall (NSUuid uuid, CXCallUpdate update, [BlockProxy (typeof (ObjCRuntime.Trampolines.NIDActionArity1V8))]global::System.Action<NSError> completion)
		if (uuid == null)
			throw new ArgumentNullException ("uuid");
		if (update == null)
			throw new ArgumentNullException ("update");
		if (completion == null)
			throw new ArgumentNullException ("completion");

Please provide a test case that shows how you could use a null `completion` parameter and crash at runtime.
Comment 3 kkurz 2016-08-22 01:50:46 UTC
I don't actually need it to *allow* a NULL handler, I probably should be providing one. That said, when I initially implemented, I simply set that field to NULL and the compiler let the application build, but it crashed at runtime. I'm not at a machine that has the preview builds installed at the moment, so I can't provide an example, but it should be as simple as calling:

ReportNewIncomingCall(new NSUuid(), update, null);
Comment 4 Sebastien Pouliot 2016-08-22 13:06:21 UTC
So it was likely an ArgumentNullException that caused your original crash.

The C# compiler does not allow enforcing non-null attributes. All the .NET BCL and our bindings enforce such checks at runtime.

We're looking how some additional tooling (e.g. roslyn code analyzers) could help spot such issues but this are not planned for the immediate future.