Skip to content

Commit 241cec1

Browse files
Fix, for now, weird subclassing of MTRDevice and MTRDeviceController. (project-chip#35833)
Some of our API consumers are apparently relying on implementation details. Stop breaking them for now, until they can fix that.
1 parent e754c22 commit 241cec1

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+9
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@ - (instancetype)initForSubclassesWithNodeID:(NSNumber *)nodeID controller:(MTRDe
295295
return self;
296296
}
297297

298+
// For now, implement an initWithNodeID in case some sub-class outside the
299+
// framework called it (by manually declaring it, even though it's not public
300+
// API). Ideally we would not have this thing, since its signature does not
301+
// match the initWithNodeID signatures of our subclasses.
302+
- (instancetype)initWithNodeID:(NSNumber *)nodeID controller:(MTRDeviceController *)controller
303+
{
304+
return [self initForSubclassesWithNodeID:nodeID controller:controller];
305+
}
306+
298307
- (void)dealloc
299308
{
300309
[[NSNotificationCenter defaultCenter] removeObserver:_systemTimeChangeObserverToken];

src/darwin/Framework/CHIP/MTRDeviceController.mm

+5-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,11 @@ - (MTRBaseDevice *)baseDeviceForNodeID:(NSNumber *)nodeID
418418
- (MTRDevice *)_setupDeviceForNodeID:(NSNumber *)nodeID prefetchedClusterData:(NSDictionary<MTRClusterPath *, MTRDeviceClusterData *> *)prefetchedClusterData
419419
{
420420
MTR_ABSTRACT_METHOD();
421-
return nil;
421+
// We promise to not return nil from this API... return an MTRDevice
422+
// instance, which will largely not be able to do anything useful. This
423+
// only matters when someone subclasses MTRDeviceController in a weird way,
424+
// then tries to create an MTRDevice from their subclass.
425+
return [[MTRDevice alloc] initForSubclassesWithNodeID:nodeID controller:self];
422426
}
423427

424428
- (MTRDevice *)deviceForNodeID:(NSNumber *)nodeID

0 commit comments

Comments
 (0)