Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeze objects: isFrozen and linkingObjects don't work #6568

Closed
pkrmf opened this issue Jun 9, 2020 · 4 comments · Fixed by #6570
Closed

Freeze objects: isFrozen and linkingObjects don't work #6568

pkrmf opened this issue Jun 9, 2020 · 4 comments · Fixed by #6570

Comments

@pkrmf
Copy link

pkrmf commented Jun 9, 2020

Goals

Generate a frozen copy of an RLMObject subclass

Expected Results

The generated frozen object should return true. The frozen object should be able to access its linking objects.

Actual Results

The generated frozen object returns false to isFrozen. Accessing its linkingObjects generates an EXC_BAD_ACCESS crash

Crash:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x50)
  * frame #0: 0x00000001037a4509 Realm`___ZN12_GLOBAL__N_113managedGetterEP11RLMPropertyPKc_block_invoke_2 + 194
    frame #1: 0x00000001036914f3 RLMTests`implicit closure #2 in RLMTests.testImmutableCopies() at <compiler-generated>:0
    frame #2: 0x0000000103691580 RLMTests`partial apply for implicit closure #2 in RLMTests.testImmutableCopies() at <compiler-generated>:0
    frame #3: 0x000000010401d39f libXCTestSwiftSupport.dylib`partial apply forwarder for closure #1 () throws -> () in XCTest.XCTAssertNil(_: @autoclosure () throws -> Swift.Optional<Any>, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () + 31
    frame #4: 0x000000010401e019 libXCTestSwiftSupport.dylib`partial apply forwarder for closure #1 () throws -> () in XCTest.XCTAssertNotNil(_: @autoclosure () throws -> Swift.Optional<Any>, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () + 9
    frame #5: 0x000000010401df0b libXCTestSwiftSupport.dylib`partial apply forwarder for closure #1 () -> () in XCTest._XCTRunThrowableBlock(() throws -> ()) -> XCTest._XCTThrowableBlockResult + 27
    frame #6: 0x000000010401df61 libXCTestSwiftSupport.dylib`partial apply forwarder for reabstraction thunk helper from @callee_guaranteed () -> () to @escaping @callee_guaranteed () -> () + 17
    frame #7: 0x000000010401308e libXCTestSwiftSupport.dylib`reabstraction thunk helper from @escaping @callee_guaranteed () -> () to @callee_unowned @convention(block) () -> () + 14
    frame #8: 0x000000010401276e libXCTestSwiftSupport.dylib`_XCTRunThrowableBlockBridge + 46
    frame #9: 0x0000000104012df4 libXCTestSwiftSupport.dylib`XCTest._XCTRunThrowableBlock(() throws -> ()) -> XCTest._XCTThrowableBlockResult + 244
    frame #10: 0x0000000104013deb libXCTestSwiftSupport.dylib`XCTest.XCTAssertNotNil(_: @autoclosure () throws -> Swift.Optional<Any>, _: @autoclosure () -> Swift.String, file: Swift.StaticString, line: Swift.UInt) -> () + 107
    frame #11: 0x000000010369118a RLMTests`RLMTests.testImmutableCopies(self=0x00007fdf48f2ce80) at RLMTests.testImmutableCopies:580:9
    frame #12: 0x00000001036915da RLMTests`@objc RLMTests.testImmutableCopies() at <compiler-generated>:0
    frame #13: 0x00007fff23c7820c CoreFoundation`__invoking___ + 140
    frame #14: 0x00007fff23c753af CoreFoundation`-[NSInvocation invoke] + 319
    frame #15: 0x00000001014f8821 XCTest`__24-[XCTestCase invokeTest]_block_invoke.208 + 78
    frame #16: 0x00000001015529b9 XCTest`-[XCTestCase(Failures) performFailableBlock:testCaseRun:shouldInterruptTest:] + 57
    frame #17: 0x00000001015528d7 XCTest`-[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 96
    frame #18: 0x00000001014f830a XCTest`__24-[XCTestCase invokeTest]_block_invoke + 1153
    frame #19: 0x00000001014f7de2 XCTest`-[XCTestCase testContextPerformInScope:] + 211
    frame #20: 0x00000001014f7e7c XCTest`-[XCTestCase invokeTest] + 137
    frame #21: 0x00000001014f9bed XCTest`__26-[XCTestCase performTest:]_block_invoke_2 + 43
    frame #22: 0x00000001015529b9 XCTest`-[XCTestCase(Failures) performFailableBlock:testCaseRun:shouldInterruptTest:] + 57
    frame #23: 0x00000001015528d7 XCTest`-[XCTestCase(Failures) _performTurningExceptionsIntoFailuresInterruptAfterHandling:block:] + 96
    frame #24: 0x00000001014f9b04 XCTest`__26-[XCTestCase performTest:]_block_invoke.334 + 88
    frame #25: 0x0000000101566302 XCTest`+[XCTContext runInContextForTestCase:block:] + 219
    frame #26: 0x00000001014f9273 XCTest`-[XCTestCase performTest:] + 668
    frame #27: 0x000000010153e807 XCTest`-[XCTest runTest] + 57
    frame #28: 0x00000001014f384a XCTest`__27-[XCTestSuite performTest:]_block_invoke + 365
    frame #29: 0x00000001014f2f74 XCTest`-[XCTestSuite _performProtectedSectionForTest:testSection:] + 54
    frame #30: 0x00000001014f3271 XCTest`-[XCTestSuite performTest:] + 355
    frame #31: 0x000000010153e807 XCTest`-[XCTest runTest] + 57
    frame #32: 0x00000001014f384a XCTest`__27-[XCTestSuite performTest:]_block_invoke + 365
    frame #33: 0x00000001014f2f74 XCTest`-[XCTestSuite _performProtectedSectionForTest:testSection:] + 54
    frame #34: 0x00000001014f3271 XCTest`-[XCTestSuite performTest:] + 355
    frame #35: 0x000000010153e807 XCTest`-[XCTest runTest] + 57
    frame #36: 0x00000001014f384a XCTest`__27-[XCTestSuite performTest:]_block_invoke + 365
    frame #37: 0x00000001014f2f74 XCTest`-[XCTestSuite _performProtectedSectionForTest:testSection:] + 54
    frame #38: 0x00000001014f3271 XCTest`-[XCTestSuite performTest:] + 355
    frame #39: 0x000000010153e807 XCTest`-[XCTest runTest] + 57
    frame #40: 0x000000010157528e XCTest`__44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke + 171
    frame #41: 0x0000000101575391 XCTest`__44-[XCTTestRunSession runTestsAndReturnError:]_block_invoke.84 + 118
    frame #42: 0x000000010150d593 XCTest`-[XCTestObservationCenter _observeTestExecutionForBlock:] + 588
    frame #43: 0x000000010157504d XCTest`-[XCTTestRunSession runTestsAndReturnError:] + 623
    frame #44: 0x00000001014d6dd7 XCTest`-[XCTestDriver runTestsAndReturnError:] + 456
    frame #45: 0x0000000101562554 XCTest`_XCTestMain + 2484
    frame #46: 0x000000010118ac1b xctest`main + 267
    frame #47: 0x00007fff5227ec25 libdyld.dylib`start + 1
(lldb) ## Steps to Reproduce

Code Sample

func testImmutableCopies() throws {
        let realm = RLMRealm.default()
        let person = Person()
        person.name = "Jennifer"
        person.age = "77"
        try realm.transaction {
            realm.add(person)
        }
        let newPerson  = person.freeze()
        XCTAssertTrue(newPerson.isFrozen) //This line fails
}
    func testImmutableLinkingObjecta() throws {
        let realm = RLMRealm.default()
        
        let person = Person()
        person.name = "Jennifer"
        person.age = "77"
        
        let dog = Dog()
        dog.name = "Max"
        dog.owner = person
        try realm.transaction {
            realm.add(person)
            realm.add(dog)
        }
        let newPerson  = person.freeze()
        XCTAssertNotNil(newPerson.dog) // This line crashes
}
@objcMembers public class Person: RLMObject {
    override init() {
        super.init()
    }
    public override class func primaryKey() -> String? {
        return "name"
    }
    
    @objc dynamic var dog: RLMLinkingObjects<Dog>?
    @objc dynamic var name: String?
    @objc dynamic var date: Date?
    @objc dynamic var age: String?

    @objc public override class func linkingObjectsProperties() -> [String : RLMPropertyDescriptor] {
        return ["dog": RLMPropertyDescriptor.init(with: Dog.self, propertyName: "owner")]
    }
    @objc dynamic var _dog: Dog? {
        return self.dog?.firstObject() as? Dog
    }
}
@objcMembers open class Dog: RLMObject {
    @objc dynamic var name: NSString?
    @objc dynamic var owner: Person?

    override init() {
        super.init()
    }
}

Version of Realm and Tooling

Realm framework version: ? Realm Cocoa 5.0.2

Realm Object Server version: ? N/A

Xcode version: 11.3.1

iOS/OSX version: Simulator iOS 13

Dependency manager + version: Swift Package Manager

@pkrmf
Copy link
Author

pkrmf commented Jun 9, 2020

Why a frozen object calling isFrozen in this test returns false? https://github.com/realm/realm-cocoa/blob/9ff304e58edce3f22ee0676d818c604906076e4b/Realm/Tests/ObjectTests.m#L1357

On top of that, I don't see where RLMObject has isFrozen implemented anywhere :S

The array test, instead, returns true when calling isFrozen on a frozen array:
https://github.com/realm/realm-cocoa/blob/9ff304e58edce3f22ee0676d818c604906076e4b/Realm/Tests/ArrayPropertyTests.m#L1496

@tgoyne
Copy link
Member

tgoyne commented Jun 9, 2020

Yeah, that test is clearly nonsense.

@tgoyne tgoyne self-assigned this Jun 9, 2020
@tgoyne tgoyne added the T-Bug label Jun 9, 2020
@pkrmf
Copy link
Author

pkrmf commented Jun 9, 2020

@tgoyne Anything regarding the crash? We should be able to access linkingobjects on a frozen copy correct?

@pkrmf
Copy link
Author

pkrmf commented Jun 10, 2020

Thanks @tgoyne for fixing it! Do you know more or less when a new version with your changes will be released?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants