diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a549a6a3c..caf553fc66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,8 +4,8 @@ x.y.z Release notes (yyyy-MM-dd) * Add support for including Realm via Swift Package Manager. ### Fixed -* ([#????](https://github.com/realm/realm-js/issues/????), since v?.?.?) -* None. +* Attempting to observe an unmanaged LinkingObjects object crashed rather than + throwing an approriate exception (since v0.100.0). diff --git a/Realm/RLMResults.mm b/Realm/RLMResults.mm index de086ce7cd..d1593a9e0d 100644 --- a/Realm/RLMResults.mm +++ b/Realm/RLMResults.mm @@ -483,6 +483,9 @@ - (RLMFastEnumerator *)fastEnumerator { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wmismatched-parameter-types" - (RLMNotificationToken *)addNotificationBlock:(void (^)(RLMResults *, RLMCollectionChange *, NSError *))block { + if (!_realm) { + @throw RLMException(@"Linking objects notifications are only supported on managed objects."); + } [_realm verifyNotificationsAreSupported:true]; return RLMAddNotificationBlock(self, _results, block, true); } diff --git a/Realm/Tests/LinkingObjectsTests.mm b/Realm/Tests/LinkingObjectsTests.mm index 29c5fecba6..3141657738 100644 --- a/Realm/Tests/LinkingObjectsTests.mm +++ b/Realm/Tests/LinkingObjectsTests.mm @@ -82,6 +82,9 @@ - (void)testLinkingObjectsOnUnmanagedObject { PersonObject *mark = [[PersonObject alloc] initWithValue:@[ @"Mark", @30, @[] ]]; XCTAssertEqual(NSNotFound, [don.parents indexOfObject:mark]); XCTAssertEqual(NSNotFound, [don.parents indexOfObjectWhere:@"TRUEPREDICATE"]); + + RLMAssertThrowsWithReason(([don.parents addNotificationBlock:^(RLMResults *, RLMCollectionChange *, NSError *) { }]), + @"Linking objects notifications are only supported on managed objects."); } - (void)testFilteredLinkingObjects {