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

获取所有upload任务时报空指针NullPointerException #573

Closed
wuMaoTou opened this issue Dec 20, 2019 · 6 comments
Closed

获取所有upload任务时报空指针NullPointerException #573

wuMaoTou opened this issue Dec 20, 2019 · 6 comments
Labels
bug

Comments

@wuMaoTou
Copy link

@wuMaoTou wuMaoTou commented Dec 20, 2019

在MainActivity调用获取全部upload任务时报空指针异常,崩溃了

版本

  • 框架版本
    version 3.7.9

  • 系统版本
    android 6.0

错误日志

java.lang.NullPointerException: Attempt to get length of null array
at com.arialyy.aria.orm.DelegateFind.exeNormalDataSql(DelegateFind.java:421)
at com.arialyy.aria.orm.DelegateFind.findAllData(DelegateFind.java:410)
at com.arialyy.aria.orm.DelegateWrapper.findAllData(DelegateWrapper.java:131)
at com.arialyy.aria.orm.DbEntity.findAllData(DbEntity.java:100)
at com.arialyy.aria.core.upload.UploadReceiver.getTaskList(UploadReceiver.java:165)
at com.arialyy.simple.MainActivity.onBackPressed(MainActivity.java:183)

重现步骤

1.在MainActivity调用获取全部upload任务崩溃了
Aria.upload(this).getTaskList();

@AriaLyy

This comment has been minimized.

Copy link
Owner

@AriaLyy AriaLyy commented Dec 20, 2019

如果数据库中没有数据,该接口返回null

@wuMaoTou

This comment has been minimized.

Copy link
Author

@wuMaoTou wuMaoTou commented Dec 23, 2019

如果数据库中没有数据,该接口返回null

感谢回复,

上传任务不会写入数据库吗?
后台是有一个上传文件的任务在执行的

然后我查看代码,貌似数据库有没有数据都有可能出现这种空指针异常吧?因为这个null数组是主动给参的
方法内部不应该先做一下空校验?

 com.arialyy.aria.orm.DelegateFind** -- Line 381 主动入参null

 /**
   * 模糊查寻数据
   */
  <T extends DbEntity> List<T> findDataByFuzzy(SQLiteDatabase db, Class<T> clazz,
      String conditions) {
    db = checkDb(db);
    if (TextUtils.isEmpty(conditions)) {
      throw new IllegalArgumentException("sql语句表达式不能为null或\"\"");
    }
    if (!conditions.toUpperCase().contains("LIKE")) {
      throw new IllegalArgumentException("sql语句表达式未包含LIEK");
    }
    String sql = String.format("SELECT rowid, * FROM %s, WHERE %s", CommonUtil.getClassName(clazz),
        conditions);
    return exeNormalDataSql(db, clazz, sql, null);
  }
 com.arialyy.aria.orm.DelegateFind** -- Line 421 报了空指针异常

 /**
   * 执行查询普通数据的sql语句,并创建对象
   *
   * @param sql sql 查询语句
   * @param selectionArgs 查询参数,如何sql语句中查询条件含有'?'则该参数不能为空
   */
  private <T extends DbEntity> List<T> exeNormalDataSql(SQLiteDatabase db, Class<T> clazz,
      String sql, String[] selectionArgs) {
    String[] temp = new String[selectionArgs.length];
    int i = 0;
    for (String arg : selectionArgs) {
      temp[i] = encodeStr(arg);
      i++;
    }
    Cursor cursor = db.rawQuery(sql, temp);
    List<T> data = cursor.getCount() > 0 ? newInstanceEntity(clazz, cursor) : null;
    closeCursor(cursor);
    return data;
  }
@AriaLyy AriaLyy added the bug label Dec 23, 2019
@AriaLyy

This comment has been minimized.

Copy link
Owner

@AriaLyy AriaLyy commented Dec 23, 2019

感谢反馈,是有这个问题,我将在今晚晚点修复这个bug🙏

@wuMaoTou

This comment has been minimized.

Copy link
Author

@wuMaoTou wuMaoTou commented Dec 23, 2019

还有另外的一个问题是,上传任务启动成功后为什么要删除任务记录?
这样会拿不到上传中的任务列表

com.arialyy.aria.http.HttpRecordAdapter

@Override public void onPre() {
    super.onPre();
    if (getWrapper().getRequestType() == ITaskWrapper.U_HTTP) {
      RecordUtil.delTaskRecord(getEntity().getFilePath(), IRecordHandler.TYPE_UPLOAD);
    }
  }
@AriaLyy

This comment has been minimized.

Copy link
Owner

@AriaLyy AriaLyy commented Dec 23, 2019

这个不影响,这个方法是启动任务的时候调用的,http上传,由于没有断点续传的功能,这是防止一个重复上传时,数据库中有多条记录

AriaLyy added a commit that referenced this issue Dec 23, 2019
@AriaLyy

This comment has been minimized.

Copy link
Owner

@AriaLyy AriaLyy commented Dec 24, 2019

使用3.8.2

@AriaLyy AriaLyy closed this Dec 28, 2019
AriaLyy added a commit that referenced this issue Jan 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.