objectbox / objectbox-java

Android Database - first and fast, lightweight on-device vector database
https://objectbox.io
Apache License 2.0
4.38k stars 302 forks source link

write(put) data error #1086

Closed unengchen closed 2 years ago

unengchen commented 2 years ago

Describe the bug A clear and concise description in English of what the bug is.

Basic info (please complete the following information):

To Reproduce Steps to reproduce the behavior: just use box.put(bean)

Expected behavior app crash and do not catch any excption.

Code

@Override
    public long put(Log entity) {
        String date_time = entity.date_time;
        int __id2 = date_time != null ? __ID_date_time : 0;
        String content = entity.content;
        int __id3 = content != null ? __ID_content : 0;
        String operator = entity.operator;
        int __id4 = operator != null ? __ID_operator : 0;
        String log_detail = entity.log_detail;
        int __id6 = log_detail != null ? __ID_log_detail : 0;

        collect400000(cursor, 0, PUT_FLAG_FIRST,
                __id2, date_time, __id3, content,
                __id4, operator, __id6, log_detail);

        String checkout_date_time = entity.checkout_date_time;
        int __id8 = checkout_date_time != null ? __ID_checkout_date_time : 0;

        long __assignedId = collect313311(cursor, entity.id, PUT_FLAG_COMPLETE,
                __id8, checkout_date_time, 0, null,
                0, null, 0, null,
                __ID_type, entity.type, __ID_operate_type, entity.operate_type,
                __ID_uploaded, entity.uploaded ? 1 : 0, 0, 0,
                0, 0, 0, 0,
                0, 0, 0, 0);

        entity.id = __assignedId;

        return __assignedId;
    }

Logs, stack traces

2022-07-14 19:01:57.269 15472-15524/com.zcla.bankaccesscontrol A/libc: Fatal signal 7 (SIGBUS), code 2, fault addr 0xa509100a in tid 15524 (DefaultDispatch), pid 15472 (nkaccesscontrol)
2022-07-14 19:01:57.361 16233-16233/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2022-07-14 19:01:57.361 16233-16233/? A/DEBUG: Build fingerprint: 'rockchip/rk3288/rk3288:8.1.0/OPM8.190605.005/105148:userdebug/test-keys'
2022-07-14 19:01:57.361 16233-16233/? A/DEBUG: Revision: '0'
2022-07-14 19:01:57.361 16233-16233/? A/DEBUG: ABI: 'arm'
2022-07-14 19:01:57.361 16233-16233/? A/DEBUG: pid: 15472, tid: 15524, name: DefaultDispatch  >>> com.zcla.bankaccesscontrol <<<
2022-07-14 19:01:57.361 16233-16233/? A/DEBUG: signal 7 (SIGBUS), code 2 (BUS_ADRERR), fault addr 0xa509100a
2022-07-14 19:01:57.361 16233-16233/? A/DEBUG:     r0 a5085000  r1 8a4642a0  r2 a5091000  r3 00000000
2022-07-14 19:01:57.361 16233-16233/? A/DEBUG:     r4 8a464280  r5 00000000  r6 0000000c  r7 870f7bf0
2022-07-14 19:01:57.361 16233-16233/? A/DEBUG:     r8 8a403080  r9 a41fbac0  sl 00000000  fp 8a464298
2022-07-14 19:01:57.361 16233-16233/? A/DEBUG:     ip 00000003  sp 870f7b88  lr 00001000  pc 8890006c  cpsr 600b0030
2022-07-14 19:01:57.370 16233-16233/? A/DEBUG: backtrace:
2022-07-14 19:01:57.370 16233-16233/? A/DEBUG:     #00 pc 0014d06c  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.370 16233-16233/? A/DEBUG:     #01 pc 00150de1  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.370 16233-16233/? A/DEBUG:     #02 pc 0014c3bd  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.370 16233-16233/? A/DEBUG:     #03 pc 0014b3b7  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.370 16233-16233/? A/DEBUG:     #04 pc 0014ca75  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.370 16233-16233/? A/DEBUG:     #05 pc 001511e3  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.370 16233-16233/? A/DEBUG:     #06 pc 0014c6db  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.371 16233-16233/? A/DEBUG:     #07 pc 00149cc7  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.371 16233-16233/? A/DEBUG:     #08 pc 000fd0a7  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.371 16233-16233/? A/DEBUG:     #09 pc 000f6d3d  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.371 16233-16233/? A/DEBUG:     #10 pc 000f6ea1  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.371 16233-16233/? A/DEBUG:     #11 pc 000f89f9  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.371 16233-16233/? A/DEBUG:     #12 pc 000f8a73  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.371 16233-16233/? A/DEBUG:     #13 pc 000481db  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/base.apk (offset 0x32de000)
2022-07-14 19:01:57.371 16233-16233/? A/DEBUG:     #14 pc 00051849  /data/app/com.zcla.bankaccesscontrol-tRsT6oyXS9S7eQ53-2d2UA==/oat/arm/base.odex (offset 0x40000)
2022-07-14 19:01:59.496 364-364/? E//system/bin/tombstoned: Tombstone written to: /data/tombstones/tombstone_35

    --------- beginning of system

Additional context Add any other context about the problem here. when I debug this code, my app crash。

long __assignedId = collect313311(cursor, entity.id, PUT_FLAG_COMPLETE,
                __id8, checkout_date_time, 0, null,
                0, null, 0, null,
                __ID_type, entity.type, __ID_operate_type, entity.operate_type,
                __ID_uploaded, entity.uploaded ? 1 : 0, 0, 0,
                0, 0, 0, 0,
                0, 0, 0, 0);
greenrobot-team commented 2 years ago

Thanks for reporting! However, based on the tombstone you have shared I can't pinpoint the issue with ObjectBox (the tombstone does not contain libobjectbox-jni.so).

As you wrote "when I debug this code" does that mean, when stepping through the code? Or when running the debug version?

Does the crash also happen with ObjectBox 3.2.0? There were some internal changes for 3.2.1 that might cause issues on 32-bit ARM chips like yours.

unengchen commented 2 years ago

I mean when stepping through the code with objectbox version 3.2.0 and 3.2.1。 long assignedId = collect313311(cursor, entity.id, PUT_FLAG_COMPLETE, id8, checkout_date_time, 0, null, 0, null, 0, null, ID_type, entity.type, __ID_operate_type, entity.operate_type, ID_uploaded, entity.uploaded ? 1 : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); my app crash,and I do not catch any expection, so I copy the logcat info when app crash,but I am sure that the issues happen in objectbox. because cancel running about the objectbox code,app is normal,the issues has no happen.

and find data from objectbox is normal, just put data and remove data is crash,and then, I use boxstore delete all files,put data and remove data is normal,

unengchen commented 2 years ago

my entity class

@Entity
public class Log {

    @Id
    public long id;
    public int type;
    public String date_time;
    public String content;
    public String operator;
    public int operate_type;  // 1-入库,2-出库
    public String log_detail;
    public boolean uploaded = false;

    // 出库打卡时间,为了合并到入库记录,导出日志
    public String checkout_date_time;

    public Log(){

    }

    public Log(int type, String date_time, String content,String operator) {
        this();
        this.type = type;
        this.date_time = date_time;
        this.content = content;
        this.operator = operator;
        this.checkout_date_time = "";
    }
}
greenrobot-team commented 2 years ago

Tried to reproduce on

As said before, given that the tombstone does not seem to include libobjectbox-jni.so I'm not sure if this is an ObjectBox issue.

@unengchen Can you show the code that puts the object? Or maybe even share a small example project that reproduces this issue?

unengchen commented 2 years ago

that is the code:

GlobalScope.launch(Dispatchers.IO) {
            try {
                val dateTime = TimeUtils.millis2String(DateTimeManager.timestamp)
                val log = Log(logType, dateTime, logContent, operator.name)
                log.operate_type = operateType
                val persons = arrayListOf<Person>()
                persons.add(operator)
                val personList = gson.toJson(persons)
                log.uploaded = SocketSendHelper.uploadLog(log, personList)

                val takeImage = operator.image
                if (!StringUtils.isTrimEmpty(takeImage)) {
                    val imageBytes = Base64.decode(takeImage, Base64.DEFAULT)
                    val bitmap = ImageUtils.bytes2Bitmap(imageBytes)
                    val photoPath =
                        AppManager.logDir + File.separator + "log_${operator.timestamp}.jpg"
                    val save =
                        ImageUtils.save(bitmap, photoPath, Bitmap.CompressFormat.JPEG, 60, true)
                    if (save) {
                        // 保存图片成功
                        operator.takeImagePath = photoPath
                    }
                    LogUtils.d("保存日志图片路径", photoPath)
                }
                persons.clear()
                val person = Person(operator.code, operator.name, operator.role)
                person.image = ""
                person.takeImagePath = operator.takeImagePath
                person.authTime = operator.authTime
                person.type = operator.type
                persons.add(person)
                log.log_detail = gson.toJson(persons)
                ObjectBoxManager.getLogBox().put(log)

                if (logType == LOG_TYPE_CHECK_IN_OUT && operateType == OPERATE_TYPE_OUT) {
                    // 入库打卡记录增加出库时间
                    val checkInLog = getCheckInLog(operator.name) ?: return@launch
                    checkInLog.checkout_date_time = dateTime
                    ObjectBoxManager.getLogBox().put(checkInLog)
                }

            } catch (e: Exception) {
                ToastUtils.showLong("保存日志$logType:${e.message}")
            }
        }
greenrobot-team commented 2 years ago

Sorry, not seeing any obvious issue. Can also debug when doing put inside a coroutine.

If you want us to continue looking into this, please share a small example project that reproduces this issue.

github-actions[bot] commented 2 years ago

Without additional information, we are unfortunately not sure how to resolve this issue. Therefore this issue has been automatically closed. Feel free to comment with additional details and we can re-open this issue.