realm-java: SIGSEV Crash on findAll() query

I’m using a Nexus 6P running 6.0.1, with Realm 1.1.0.

This just started, but I am now consistently getting a crash:

07-08 09:36:34.972 739-860/com.app.dev.debug A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0x7f6ed56cf0 in tid 860 (IntentService[C)
07-08 09:36:35.075 511-511/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
07-08 09:36:35.076 511-511/? A/DEBUG: Build fingerprint: 'google/angler/angler:6.0.1/MTC19V/2862947:user/release-keys'
07-08 09:36:35.076 511-511/? A/DEBUG: Revision: '0'
07-08 09:36:35.076 511-511/? A/DEBUG: ABI: 'arm64'
07-08 09:36:35.076 511-511/? A/DEBUG: pid: 739, tid: 860, name: IntentService[C  >>> com.app.dev.debug <<<
07-08 09:36:35.076 511-511/? A/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0x7f6ed56cf0
07-08 09:36:35.103 511-511/? A/DEBUG:     x0   0000007f6eb3d8e0  x1   0000000000000031  x2   0000007f6ed56cf0  x3   0000000000000000
07-08 09:36:35.103 511-511/? A/DEBUG:     x4   0000000000000000  x5   0000000000000000  x6   0000000000000001  x7   0000007f675214f0
07-08 09:36:35.104 511-511/? A/DEBUG:     x8   0000000000000000  x9   0000007f675214f0  x10  0000000000000001  x11  0000007f6e9cc260
07-08 09:36:35.104 511-511/? A/DEBUG:     x12  0000007f8ab01b40  x13  00000000000000c6  x14  00000000000000c7  x15  0000000000000064
07-08 09:36:35.104 511-511/? A/DEBUG:     x16  0000000000000065  x17  0000007f8ab01000  x18  0000007f6e9cc260  x19  0000007f6ed56cf0
07-08 09:36:35.104 511-511/? A/DEBUG:     x20  0000007f6e948100  x21  0000007f67520838  x22  0000007f67520820  x23  0000007f67520970
07-08 09:36:35.104 511-511/? A/DEBUG:     x24  0000000000000032  x25  0000000000000000  x26  0000000000000005  x27  0000000000000000
07-08 09:36:35.104 511-511/? A/DEBUG:     x28  0000000000000003  x29  0000007f67520740  x30  0000007f6fbace44
07-08 09:36:35.105 511-511/? A/DEBUG:     sp   0000007f67520740  pc   0000007f6ed56cf0  pstate 0000000080000000
07-08 09:36:35.117 511-511/? A/DEBUG: backtrace:
07-08 09:36:35.117 511-511/? A/DEBUG:     #00 pc 00000000008d6cf0  [anon:libc_malloc]
07-08 09:36:35.118 511-511/? A/DEBUG:     #01 pc 0000000000044e40  /data/app/com.app.dev.debug-1/lib/arm64/librealm-jni.so
07-08 09:36:35.118 511-511/? A/DEBUG:     #02 pc 0000000000045204  /data/app/com.app.dev.debug-1/lib/arm64/librealm-jni.so
07-08 09:36:35.118 511-511/? A/DEBUG:     #03 pc 00000000000459e8  /data/app/com.app.dev.debug-1/lib/arm64/librealm-jni.so
07-08 09:36:35.118 511-511/? A/DEBUG:     #04 pc 00000000000ae798  /data/app/com.app.dev.debug-1/lib/arm64/librealm-jni.so
07-08 09:36:35.118 511-511/? A/DEBUG:     #05 pc 00000000000644b8  /data/app/com.app.dev.debug-1/lib/arm64/librealm-jni.so
07-08 09:36:35.118 511-511/? A/DEBUG:     #06 pc 00000000000655b4  /data/app/com.app.dev.debug-1/lib/arm64/librealm-jni.so
07-08 09:36:35.119 511-511/? A/DEBUG:     #07 pc 00000000000b3684  /data/app/com.app.dev.debug-1/lib/arm64/librealm-jni.so
07-08 09:36:35.119 511-511/? A/DEBUG:     #08 pc 00000000000ac9d4  /data/app/com.app.dev.debug-1/lib/arm64/librealm-jni.so
07-08 09:36:35.119 511-511/? A/DEBUG:     #09 pc 00000000000b7c7c  /data/app/com.app.dev.debug-1/lib/arm64/librealm-jni.so
07-08 09:36:35.119 511-511/? A/DEBUG:     #10 pc 00000000000b7ee4  /data/app/com.app.dev.debug-1/lib/arm64/librealm-jni.so
07-08 09:36:35.119 511-511/? A/DEBUG:     #11 pc 00000000000b89a0  /data/app/com.app.dev.debug-1/lib/arm64/librealm-jni.so
07-08 09:36:35.119 511-511/? A/DEBUG:     #12 pc 000000000004e868  /data/app/com.app.dev.debug-1/lib/arm64/librealm-jni.so (Java_io_realm_internal_TableQuery_nativeFindAll+268)
07-08 09:36:35.119 511-511/? A/DEBUG:     #13 pc 0000000001c6bfcc  /data/app/com.app.dev.debug-1/oat/arm64/base.odex (offset 0xb18000) (long io.realm.internal.TableQuery.nativeFindAll(long, long, long, long)+160)
07-08 09:36:35.120 511-511/? A/DEBUG:     #14 pc 0000000001c6e1dc  /data/app/com.app.dev.debug-1/oat/arm64/base.odex (offset 0xb18000) (io.realm.internal.TableView io.realm.internal.TableQuery.findAll()+224)
07-08 09:36:35.120 511-511/? A/DEBUG:     #15 pc 0000000001be00a8  /data/app/com.app.dev.debug-1/oat/arm64/base.odex (offset 0xb18000) (io.realm.RealmResults io.realm.RealmQuery.findAll()+380)
07-08 09:36:35.120 511-511/? A/DEBUG:     #16 pc 0000000001302544  /data/app/com.app.dev.debug-1/oat/arm64/base.odex (offset 0xb18000) (void com.app.services.ChecklistIntentService.getAnswers(android.content.Intent)+824)
07-08 09:36:35.120 511-511/? A/DEBUG:     #17 pc 0000000001302b80  /data/app/com.app.dev.debug-1/oat/arm64/base.odex (offset 0xb18000) (void com.app.services.ChecklistIntentService.doWork(android.content.Intent)+244)
07-08 09:36:35.120 511-511/? A/DEBUG:     #18 pc 000000000130140c  /data/app/com.app.dev.debug-1/oat/arm64/base.odex (offset 0xb18000) (void com.app.services.RealmBackgroundIntentService.onHandleIntent(android.content.Intent)+608)
07-08 09:36:35.120 511-511/? A/DEBUG:     #19 pc 0000000073dafdb8  /data/dalvik-cache/arm64/system@framework@boot.oat (offset 0x1ede000)

My ChecklistIntentService getAnswers() looks like this:

    private void getAnswers(Intent intent) {
        final String villageId = intent.getStringExtra(Actions.KEY_ID);

        // CHECKLIST ANSWERS
        try {
            final Call<List<ChecklistItemStatus>> answersCall = service.getChecklistAnswers(villageId);
            final Response<List<ChecklistItemStatus>> answersResponse = answersCall.execute();

            if (answersResponse.isSuccessful()) {
                final List<ChecklistItemStatus> answers = answersResponse.body();

                 // we have to manually create a composite primary key from 2 fields.
                for (ChecklistItemStatus item : answers) {

                    // IT LOOKS LIKE THIS IS WHAT'S CRASHING
                    RealmResults<Checklist> checklistsRealmResults = realm.where(Checklist.class).equalTo("items.id", item.getChecklistItemId()).findAll();

                    if (checklistsRealmResults != null && checklistsRealmResults.isValid() && !checklistsRealmResults.isEmpty()) {
                        item.setChecklistId(checklistsRealmResults.get(0).getId());
                    }
                    item.setId(item.getVillageId() + item.getChecklistItemId());

                    realm.beginTransaction();
                    realm.copyToRealmOrUpdate(answers);
                    realm.commitTransaction();
                }
            }
            else {
                logException(answersResponse,gson);
            }
        } catch (Exception e) {
            Timber.e(e, "Couldn't get checklist answers.");
        }

    }

and the model looks like this (getters and setters omitted for brevity:

public class Checklist extends RealmObject {
    @PrimaryKey
    private String id;
    private String name;
    private String description;
    private String url;
    private int sequence;
    private int totalItems;
    private RealmList<ChecklistItem> items;
}
public class ChecklistItem extends RealmObject {
    @PrimaryKey
    private String id;
    private String name;
    private String description;
    private String url;
    private int sequence;
}
public class ChecklistItemStatus extends RealmObject {
    @PrimaryKey
    private String id;
    @Index
    private String villageId;
    @Index
    private String checklistId;
    @Index
    private String checklistItemId;
    @Index
    private Integer status;
}

Please let me know if there’s any other information I can provide.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 18 (12 by maintainers)

Most upvoted comments

By the way, your code will be more stable if you do

                realm.beginTransaction();
                for (ChecklistItemStatus item : answers) {

                    // IT LOOKS LIKE THIS IS WHAT'S CRASHING
                    RealmResults<Checklist> checklistsRealmResults = realm.where(Checklist.class).equalTo("items.id", item.getChecklistItemId()).findAll();

                    if (checklistsRealmResults != null && checklistsRealmResults.isValid() && !checklistsRealmResults.isEmpty()) {
                        item.setChecklistId(checklistsRealmResults.get(0).getId());
                    }
                    item.setId(item.getVillageId() + item.getChecklistItemId());
                    realm.copyToRealmOrUpdate(answers);
                }
                realm.commitTransaction();

It’s even better if you use executeTransaction() instead, which does cancelTransaction() on exception.