Do something sane-ish if someone tries to create MTRDevice with a null nodeID. (#35830)
* Do something sane-ish if someone tries to create MTRDevice with a null nodeID.
* Add log per review comment.
diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm
index 6e3e798..bc298b7 100644
--- a/src/darwin/Framework/CHIP/MTRDevice.mm
+++ b/src/darwin/Framework/CHIP/MTRDevice.mm
@@ -314,6 +314,17 @@
+ (MTRDevice *)deviceWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller
{
+ if (nodeID == nil || controller == nil) {
+ // These are not nullable in our API, but clearly someone is not
+ // actually turning on the relevant compiler checks (or is doing dynamic
+ // dispatch with bad values). While we promise to not return nil from
+ // this method, if the caller is ignoring the nullability API contract,
+ // there's not much we can do here.
+ MTR_LOG_ERROR("Can't create device with nodeID: %@, controller: %@",
+ nodeID, controller);
+ return nil;
+ }
+
return [controller deviceForNodeID:nodeID];
}