Skip to content

"Invalid null value for non-nullable property" crash when creating model object #8759

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

Open
michalrentka opened this issue Apr 23, 2025 · 0 comments

Comments

@michalrentka
Copy link

How frequently does the bug occur?

Sometimes

Description

Some users are reporting crashes when an object is created in background thread. The object is defined like this:

final class RItemField: EmbeddedObject {
    @Persisted var key: String
    @Persisted var baseKey: String?
    @Persisted var value: String
    @Persisted var changed: Bool
}

And part of the code that crashes is:

override func addFields(for annotation: PDFDocumentAnnotation, to item: RItem, database: Realm) {
        super.addFields(for: annotation, to: item, database: database)

        for field in FieldKeys.Item.Annotation.extraPDFFields(for: annotation.type) {
            let rField = RItemField()
            rField.key = field.key
            rField.baseKey = field.baseKey
            rField.changed = true

            switch field.key {
            case FieldKeys.Item.Annotation.Position.pageIndex where field.baseKey == FieldKeys.Item.Annotation.position:
                rField.value = "\(annotation.page)"

            case FieldKeys.Item.Annotation.Position.lineWidth where field.baseKey == FieldKeys.Item.Annotation.position:
                rField.value = annotation.lineWidth.flatMap({ "\(Decimal($0).rounded(to: 3))" }) ?? ""

            case FieldKeys.Item.Annotation.pageLabel:
                rField.value = annotation.pageLabel

            case FieldKeys.Item.Annotation.Position.rotation where field.baseKey == FieldKeys.Item.Annotation.position:
                rField.value = "\(annotation.rotation ?? 0)"

            case FieldKeys.Item.Annotation.Position.fontSize where field.baseKey == FieldKeys.Item.Annotation.position:
                rField.value = "\(annotation.fontSize ?? 0)"

            default:
                DDLogWarn("CreatePDFAnnotationsDbRequest: unknown field, assigning empty value - \(field.key)")
                rField.value = ""
            }

            item.fields.append(rField)
        }
    }

As you can see the RItemField.value is defined as String and the value is always assigned as some string, so I don't know how I can fix this so that it doesn't become null afterwards. Any ideas?

Stacktrace & log output

Incident Identifier: D86DB6B1-5331-4151-9F2F-AEBE046494A6
Hardware Model:      iPad7,11
Process:         Zotero [77755]
Path:            /private/var/containers/Bundle/Application/9C7A887C-8586-4F5F-BF4D-FC48F52FE0AA/Zotero.app/Zotero
Identifier:      org.zotero.ios.Zotero
Version:         1.0.49 (322)
Code Type:       ARM-64
Parent Process:   [1]

Date/Time:       2025-04-21 07:28:42 +0000
OS Version:      iPhone OS 18.1.1 (22B91)
Report Version:  104

Exception Type:  SIGABRT
Exception Codes: #0 at 0x1dadd1f1c
Crashed Thread:  2

Application Specific Information:
*** Terminating app due to uncaught exception 'RLMException', reason: 'Invalid null value for non-nullable property 'RItemField.value'.'

Last Exception Backtrace:
0   CoreFoundation                      0x0000000190ab186c 0x190a34000 + 514156
1   libobjc.A.dylib                     0x000000018e086494 0x18e074000 + 74900
2   RealmSwift                          RLMAccessorContext::createObject(objc_object*, realm::CreatePolicy, bool, realm::ObjKey) (in RealmSwift) (RLMAccessor.mm:0)
3   RealmSwift                          realm::Obj RLMAccessorContext::unbox<realm::Obj>(objc_object*, realm::CreatePolicy, realm::ObjKey) (in RealmSwift) (RLMAccessor.mm:1152)
4   RealmSwift                          void realm::List::insert<objc_object* const __strong&, RLMAccessorContext>(RLMAccessorContext&, unsigned long, objc_object* const __strong&, realm::CreatePolicy) (in RealmSwift) (object_accessor.hpp:0)
5   RealmSwift                          invocation function for block in RLMInsertObject(RLMManagedArray*, objc_object*, unsigned long) (in RealmSwift) (RLMManagedArray.mm:215)
6   RealmSwift                          auto translateCollectionError<void () block_pointer __strong&>(void () block_pointer __strong&, NSString*) (in RealmSwift) (RLMResults_Private.hpp:65)
7   RealmSwift                          changeArray(RLMManagedArray*, NSKeyValueChange, unsigned long, void () block_pointer) (in RealmSwift) (RLMManagedArray.mm:150)
8   RealmSwift                          RLMInsertObject(RLMManagedArray*, objc_object*, unsigned long) (in RealmSwift) (RLMManagedArray.mm:216)
9   RealmSwift                          List.append(_:) (in RealmSwift) (List.swift:112)
10  Zotero                              specialized CreatePDFAnnotationsDbRequest.addFields(for:to:database:) (in Zotero) (/<compiler-generated>:0)
11  Zotero                              CreatePDFAnnotationsDbRequest.create(annotation:parent:in:) (in Zotero) (CreatePDFAnnotationsDbRequest.swift:76)
12  Zotero                              CreatePDFAnnotationsDbRequest.process(in:) (in Zotero) (CreatePDFAnnotationsDbRequest.swift:29)
13  Zotero                              protocol witness for DbRequest.process(in:) in conformance CreatePDFAnnotationsDbRequest (in Zotero) (/<compiler-generated>:0)
14  Zotero                              partial apply for closure #1 in RealmDbCoordinator.perform(request:) (in Zotero) (/<compiler-generated>:0)
15  RealmSwift                          Realm.write<A>(withoutNotifying:_:) (in RealmSwift) (Realm.swift:265)
16  Zotero                              RealmDbCoordinator.perform(request:) (in Zotero) (RealmDbStorage.swift:0)
17  Zotero                              RealmDbStorage.perform(request:on:) (in Zotero) (RealmDbStorage.swift:81)
18  Zotero                              specialized closure #1 in BackgroundDbProcessingActionHandler.perform<A>(request:completion:) (in Zotero) (ViewModel.swift:53)
19  Zotero                              <deduplicated_symbol> (in Zotero) + 28
20  libdispatch.dylib                   0x0000000198057a7c 0x197ff7000 + 395900
21  libdispatch.dylib                   0x0000000198058a8c 0x197ff7000 + 400012
22  libdispatch.dylib                   0x0000000198001dd0 0x197ff7000 + 44496
23  libdispatch.dylib                   0x0000000198002854 0x197ff7000 + 47188
24  libdispatch.dylib                   0x000000019800c3c4 0x197ff7000 + 86980
25  libdispatch.dylib                   0x000000019800bcb0 0x197ff7000 + 85168
26  libsystem_pthread.dylib             0x00000001ed601c90 0x1ed5fe000 + 15504
27  libsystem_pthread.dylib             0x00000001ed5ff4a0 0x1ed5fe000 + 5280

Thread 0:
0   libsystem_kernel.dylib              0x00000001dadc7bd8 0x1dadc6000 + 7128
1   libsystem_kernel.dylib              0x00000001dadcb108 0x1dadc6000 + 20744
2   libsystem_kernel.dylib              0x00000001dadcaf58 0x1dadc6000 + 20312
3   CoreFoundation                      0x0000000190a84a5c 0x190a34000 + 330332
4   CoreFoundation                      0x0000000190a840fc 0x190a34000 + 327932
5   CoreFoundation                      0x0000000190a83828 0x190a34000 + 325672
6   GraphicsServices                    0x00000001d6d58840 0x1d6d57000 + 6208
7   UIKitCore                           0x00000001933cbf80 0x193029000 + 3813248
8   UIKitCore                           0x000000019347119c 0x193029000 + 4489628
9   Zotero                              0x0000000100ac40ec 0x100abc000 + 33004
10  ???                                 0x00000001b3dfc8ac 0x0 + 0

Thread 1:
0   libsystem_pthread.dylib             0x00000001ed5ff498 0x1ed5fe000 + 5272

Thread 2 Crashed:
0   libsystem_kernel.dylib              0x00000001dadd1f1c 0x1dadc6000 + 48924
1   libsystem_c.dylib                   0x00000001980e7664 0x198075000 + 468580
2   Zotero                              -[PLCrashReporter setCrashCallbacks:].cold.1 (in Zotero) (PLCrashReporter.m:0)
3   Zotero                              uncaught_exception_handler (in Zotero) (PLCrashReporter.m:361)
4   CoreFoundation                      0x0000000190ba19e4 0x190a34000 + 1497572
5   libobjc.A.dylib                     0x000000018e09b30c 0x18e074000 + 160524
6   libc++abi.dylib                     0x00000001ed5294a8 0x1ed515000 + 83112
7   libc++abi.dylib                     0x00000001ed529458 0x1ed515000 + 83032
8   libdispatch.dylib                   0x0000000198058aa0 0x197ff7000 + 400032
9   libdispatch.dylib                   0x0000000198001dd0 0x197ff7000 + 44496
10  libdispatch.dylib                   0x0000000198002854 0x197ff7000 + 47188
11  libdispatch.dylib                   0x000000019800c3c4 0x197ff7000 + 86980
12  libdispatch.dylib                   0x000000019800bcb0 0x197ff7000 + 85168
13  libsystem_pthread.dylib             0x00000001ed601c90 0x1ed5fe000 + 15504
14  libsystem_pthread.dylib             0x00000001ed5ff4a0 0x1ed5fe000 + 5280

Thread 3:
0   libsystem_pthread.dylib             0x00000001ed5ff498 0x1ed5fe000 + 5272

Thread 4:
0   libsystem_kernel.dylib              0x00000001dadc7bd8 0x1dadc6000 + 7128
1   libsystem_kernel.dylib              0x00000001dadcb108 0x1dadc6000 + 20744
2   libsystem_kernel.dylib              0x00000001dadcaf58 0x1dadc6000 + 20312
3   CoreFoundation                      0x0000000190a84a5c 0x190a34000 + 330332
4   CoreFoundation                      0x0000000190a840fc 0x190a34000 + 327932
5   CoreFoundation                      0x0000000190a83828 0x190a34000 + 325672
6   Foundation                          0x000000018f83ebec 0x18f792000 + 707564
7   Foundation                          0x000000018f83ea68 0x18f792000 + 707176
8   UIKitCore                           0x00000001933de2f8 0x193029000 + 3887864
9   Foundation                          0x000000018f84e7d4 0x18f792000 + 772052
10  libsystem_pthread.dylib             0x00000001ed602f54 0x1ed5fe000 + 20308
11  libsystem_pthread.dylib             0x00000001ed5ff4ac 0x1ed5fe000 + 5292

Thread 5:
0   libsystem_kernel.dylib              0x00000001dadc7bd8 0x1dadc6000 + 7128
1   libsystem_kernel.dylib              0x00000001dadcb108 0x1dadc6000 + 20744
2   libsystem_kernel.dylib              0x00000001dadcaf58 0x1dadc6000 + 20312
3   Zotero                              0x0000000101252f10 0x100abc000 + 7958288
4   libsystem_pthread.dylib             0x00000001ed602f54 0x1ed5fe000 + 20308
5   libsystem_pthread.dylib             0x00000001ed5ff4ac 0x1ed5fe000 + 5292

Thread 6:
0   libsystem_kernel.dylib              0x00000001dadc7968 0x1dadc6000 + 6504
1   libsystem_pthread.dylib             0x00000001ed5ff4a0 0x1ed5fe000 + 5280

Thread 7:
0   libsystem_kernel.dylib              0x00000001dadc7bd8 0x1dadc6000 + 7128
1   libsystem_kernel.dylib              0x00000001dadcb108 0x1dadc6000 + 20744
2   libsystem_kernel.dylib              0x00000001dadcaf58 0x1dadc6000 + 20312
3   CoreFoundation                      0x0000000190a84a5c 0x190a34000 + 330332
4   CoreFoundation                      0x0000000190a840fc 0x190a34000 + 327932
5   CoreFoundation                      0x0000000190a83828 0x190a34000 + 325672
6   CFNetwork                           0x0000000191f63334 0x191e75000 + 975668
7   Foundation                          0x000000018f84e7d4 0x18f792000 + 772052
8   libsystem_pthread.dylib             0x00000001ed602f54 0x1ed5fe000 + 20308
9   libsystem_pthread.dylib             0x00000001ed5ff4ac 0x1ed5fe000 + 5292

Thread 8:
0   libsystem_kernel.dylib              0x00000001dadce3b0 0x1dadc6000 + 33712
1   RealmSwift                          0x00000001018c15dc 0x1016dc000 + 1988060
2   libsystem_pthread.dylib             0x00000001ed602f54 0x1ed5fe000 + 20308
3   libsystem_pthread.dylib             0x00000001ed5ff4ac 0x1ed5fe000 + 5292

Thread 9:
0   libsystem_kernel.dylib              0x00000001dadcd168 0x1dadc6000 + 29032
1   libc++.1.dylib                      0x000000019ffeee04 0x19ffd2000 + 118276
2   PSPDFKit                            0x0000000102c181bc 0x1023dc000 + 8634812
3   PSPDFKit                            0x00000001029514e0 0x1023dc000 + 5723360
4   Foundation                          0x000000018f84e7d4 0x18f792000 + 772052
5   libsystem_pthread.dylib             0x00000001ed602f54 0x1ed5fe000 + 20308
6   libsystem_pthread.dylib             0x00000001ed5ff4ac 0x1ed5fe000 + 5292

Thread 10:
0   libobjc.A.dylib                     0x000000018e0823e4 0x18e074000 + 58340
1   Zotero                              0x0000000100e319ec 0x100abc000 + 3627500
2   Zotero                              0x0000000100e2eca0 0x100abc000 + 3615904
3   Zotero                              0x0000000100d078ac 0x100abc000 + 2406572
4   libdispatch.dylib                   0x0000000198057a7c 0x197ff7000 + 395900
5   libdispatch.dylib                   0x0000000198058a8c 0x197ff7000 + 400012
6   libdispatch.dylib                   0x0000000198001dd0 0x197ff7000 + 44496
7   libdispatch.dylib                   0x0000000198002854 0x197ff7000 + 47188
8   libdispatch.dylib                   0x000000019800c3c4 0x197ff7000 + 86980
9   libdispatch.dylib                   0x000000019800bcb0 0x197ff7000 + 85168
10  libsystem_pthread.dylib             0x00000001ed601c90 0x1ed5fe000 + 15504
11  libsystem_pthread.dylib             0x00000001ed5ff4a0 0x1ed5fe000 + 5280

Thread 11:
0   PSPDFKit                            0x0000000102f58ccc 0x1023dc000 + 12045516
1   PSPDFKit                            0x0000000102f7b3f0 0x1023dc000 + 12186608
2   PSPDFKit                            0x0000000102ec3e84 0x1023dc000 + 11435652
3   PSPDFKit                            0x0000000102ec14c8 0x1023dc000 + 11424968
4   PSPDFKit                            0x0000000102ee2094 0x1023dc000 + 11559060
5   PSPDFKit                            0x00000001027f1228 0x1023dc000 + 4280872
6   PSPDFKit                            0x00000001027ee93c 0x1023dc000 + 4270396
7   PSPDFKit                            0x00000001027ee064 0x1023dc000 + 4268132
8   PSPDFKit                            0x0000000102c41a90 0x1023dc000 + 8805008
9   PSPDFKit                            0x00000001025e9280 0x1023dc000 + 2151040
10  PSPDFKit                            0x00000001024cbcc0 0x1023dc000 + 982208
11  PSPDFKit                            0x00000001024cb718 0x1023dc000 + 980760
12  PSPDFKit                            0x00000001025401d8 0x1023dc000 + 1458648
13  PSPDFKit                            0x000000010300731c 0x1023dc000 + 12759836
14  PSPDFKit                            0x000000010253c8a8 0x1023dc000 + 1444008
15  PSPDFKit                            0x000000010253c0ec 0x1023dc000 + 1442028
16  PSPDFKit                            0x000000010255183c 0x1023dc000 + 1529916
17  PSPDFKit                            0x0000000102610b10 0x1023dc000 + 2312976
18  PSPDFKit                            0x0000000102fe5918 0x1023dc000 + 12622104
19  libdispatch.dylib                   0x000000019800883c 0x197ff7000 + 71740
20  libdispatch.dylib                   0x0000000198058a8c 0x197ff7000 + 400012
21  libdispatch.dylib                   0x0000000197ffe320 0x197ff7000 + 29472
22  libdispatch.dylib                   0x0000000197ffda24 0x197ff7000 + 27172
23  libdispatch.dylib                   0x000000019800afe0 0x197ff7000 + 81888
24  libdispatch.dylib                   0x000000019800b7c8 0x197ff7000 + 83912
25  libsystem_pthread.dylib             0x00000001ed601c54 0x1ed5fe000 + 15444
26  libsystem_pthread.dylib             0x00000001ed5ff4a0 0x1ed5fe000 + 5280

Thread 2 crashed with ARM-64 Thread State:
    pc: 0x00000001dadd1f1c     fp: 0x000000016f456710     sp: 0x000000016f4566f0     x0: 0x0000000000000000 
    x1: 0x0000000000000000     x2: 0x0000000000000000     x3: 0x0000000000000000     x4: 0x0000000000000010 
    x5: 0x00000000e220500e     x6: 0x0000000301fc88c0     x7: 0x0000000000000000     x8: 0x000000016f457000 
    x9: 0x999980a489550841    x10: 0x000000012219ce00    x11: 0x007f00012219ce00    x12: 0x0000000000000050 
   x13: 0x000000012219d2f0    x14: 0x000081a1faf59f99    x15: 0x00000001faf59f98    x16: 0x0000000000000148 
   x17: 0x0000000000000008    x18: 0x0000000000000000    x19: 0x0000000000000006    x20: 0x0000000000001103 
   x21: 0x000000016f4570e0    x22: 0x0000000302b28fc0    x23: 0x00000001ef2aa590    x24: 0x000000000000001c 
   x25: 0x0000000190eb580b    x26: 0x00000001fbf39ab8    x27: 0x00000001ef6b6000    x28: 0x0000000000000000 
    lr: 0x00000001ed604630   cpsr: 0x0000000040000000

Can you reproduce the bug?

No

Reproduction Steps

No response

Version

10.54.4

What Atlas Services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

iOS 18.1.1

Build environment

Xcode version: 16.3
Dependency manager and version: SPM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant