realm-swift
realm-swift copied to clipboard
subscript.get + 126 (PersistedProperty.swift:126)
How frequently does the bug occur?
Sometimes
Description
as the context: libobjc.A.dylib 0x16734 objc_exception_throw 2 Realm 0x92c0 getBoxedrealm::StringData + 42 (RLMObject_Private.hpp:42) 3 RealmSwift 0xfe20 _rlmGetPropertyOptional + 222 (BasicTypes.swift:222) 4 RealmSwift 0x2cee4 _rlmGetProperty + 244 (ComplexTypes.swift:244) 5 RealmSwift 0x59854 get + 182 (PersistedProperty.swift:182) 6 RealmSwift 0x5959c subscript.get + 126 (PersistedProperty.swift:126)
Stacktrace & log output
libobjc.A.dylib 0x16734 objc_exception_throw
2 Realm 0x92c0 getBoxed<realm::StringData> + 42 (RLMObject_Private.hpp:42)
3 RealmSwift 0xfe20 _rlmGetPropertyOptional + 222 (BasicTypes.swift:222)
4 RealmSwift 0x2cee4 _rlmGetProperty + 244 (ComplexTypes.swift:244)
5 RealmSwift 0x59854 get + 182 (PersistedProperty.swift:182)
6 RealmSwift 0x5959c subscript.get + 126 (PersistedProperty.swift:126)
Can you reproduce the bug?
Not yet
Reproduction Steps
No response
Version
10.25.0
What SDK flavour are you using?
Local Database only
Are you using encryption?
No, not using encryption
Platform OS and version(s)
iOS 15.4.1
Build environment
Xcode version: 13.2 Dependency manager and version:cocoapod 1.11.3
help please
Could you share the code snippet where you subscript, or share a reproduction .zip? If the object your trying to access got deleted, or you're accessing it from a different thread, that might cause the exception.
Could you share the code snippet where you subscript, or share a reproduction .zip? If the object your trying to access got deleted, or you're accessing it from a different thread, that might cause the exception.

which thread should I access the object?
Could you share the code snippet where you subscript, or share a reproduction .zip? If the object your trying to access got deleted, or you're accessing it from a different thread, that might cause the exception.
Sorry for can't provide a reproducible code snippet or zip, not all devices crashed, and I haven't reproduced the crash in my development
Hi @shadow-boy It seems this is happening while you are trying to read a property value using subscripts, are you using any subscripts for example object["password"]?.
There is no specific thread you have to do this read, but you do have to do it in the same thread as the realm thread. Check if you are doing any reading in a different thread from the one you created your realm?.
Please attach any code snippet related to what I just asked above, this will help us diagnose the issue.
Hi @shadow-boy It seems this is happening while you are trying to read a property value using subscripts, are you using any subscripts for example
object["password"]?. There is no specific thread you have to do this read, but you do have to do it in the same thread as the realm thread. Check if you are doing any reading in a different thread from the one you created your realm?. Please attach any code snippet related to what I just asked above, this will help us diagnose the issue. I don't read a property value using subscripts,but i think it's different thread as realm thread,but how can i do to keep same thread between realm thread and read thread.
I don't read a property value using subscripts,but i think it's different thread as realm thread,but how can i do to keep same thread between realm thread and read thread.
Hello @shadow-boy one good way to guarantee that you read the data from the same thread is that you don't pass realm or objects within scopes. Are you pushing any operation to another thread?, in that case create a realm for that specific thread. it could be interesting to see how are you initialising your realm? Follow this documentation https://www.mongodb.com/docs/realm/sdk/swift/advanced-guides/threading/ for best practices regarding threading.
@shadow-boy are you still encountering this issue? If so could you post a full stacktrace of the crash here so that we can investigate further.
We have an issue with similar stack trace that leads to BasicTypes.swift+222:
0 CoreFoundation 0x91d3c __exceptionPreprocess
1 libobjc.A.dylib 0x146a8 objc_exception_throw
2 CoreFoundation 0x161768 +[NSObject(NSObject) _copyDescription]
3 CoreFoundation 0x2bf6c ___forwarding___
4 CoreFoundation 0x2b1dc _CF_forwarding_prep_0
5 libswiftCore.dylib 0x18fb00 _bridgeCocoaString(_:)
6 libswiftCore.dylib 0x18fcdc String.init(_cocoaString:)
7 libswiftFoundation.dylib 0x3840 static String._unconditionallyBridgeFromObjectiveC(_:)
8 ----- 0x118bf40 protocol witness for static _PersistableInsideOptional._rlmGetPropertyOptional(_:_:) in conformance String + 222 (BasicTypes.swift:222)
9 ----- 0x118f488 static Optional<A>._rlmGetProperty(_:_:) + 244 (ComplexTypes.swift:244)
10 ----- 0x11c4af0 Persisted.get(_:) + 182 (PersistedProperty.swift:182)
11 ----- 0x11c566c static Persisted.subscript.getter + 126 (PersistedProperty.swift:126)
Crash is
Fatal Exception: NSInvalidArgumentException -[NSNull _fastCStringContents:]: unrecognized selector sent to instance 0x1f8997a90
Seems like it happens when we access an EmbeddedObject in a specific model. Accessing this embedded object and the model itself happens only on a specific queue dedicated to Realm. @leemaguire can you please take a look?
@PoltoraIvana it seems that the issue is in CoreFoundation. Do you know what the value of the string was at the time of the crash? Have you been able to reproduce this at all?
No, we are unable to reproduce it, we see it only in Crashlytics. The embedded object does contain one String, which is not optional. Something like this:
final class DbEmbeded: EmbeddedObject {
@Persisted var string: String
@Persisted var created: Date
@Persisted var creator: Int
}
Hi @PoltoraIvana it seems like the issue is happening when trying to read an Optional String property. The weird thing is you mention this is happening while trying to read a Not Optional String, can you confirm this? In that case, this may be happening because it is trying to cast a nil into a not nil type, but like I said this is something that should not be happening. Another reason could be that the data stored in the database cannot be casted to Swift, are you storing any "strange" data in the database. A final reason for this to be happening it is that the data is corrupted. A way to reproduce this, is to ask an affected user the realm file, we can then check the data and check for corrupted entries or try to reproduce the issue.
@PoltoraIvana do you have any follow up for Diana's last comment?
we don't have these crashes happening anymore, if we do stumble upon them, I will try to get the realm file of the affected user. Thanks