From 2c0436216f6f0bc2403986aa2771af03b1e4a91c Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Tue, 18 Sep 2018 10:04:12 -0400 Subject: [PATCH] Prevent null strings in modules/repos Close #620, close #621 --- .../magisk/adapters/ModulesAdapter.java | 6 ++--- .../magisk/adapters/ReposAdapter.java | 13 +++++++---- .../magisk/container/BaseModule.java | 22 ++++++++++++------- .../com/topjohnwu/magisk/container/Repo.java | 3 ++- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/app/src/full/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java b/app/src/full/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java index e31151c60..6a978ab00 100644 --- a/app/src/full/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java +++ b/app/src/full/java/com/topjohnwu/magisk/adapters/ModulesAdapter.java @@ -45,9 +45,9 @@ public class ModulesAdapter extends RecyclerView.Adapter diff --git a/app/src/full/java/com/topjohnwu/magisk/container/BaseModule.java b/app/src/full/java/com/topjohnwu/magisk/container/BaseModule.java index 594cb6e8d..194f7e002 100644 --- a/app/src/full/java/com/topjohnwu/magisk/container/BaseModule.java +++ b/app/src/full/java/com/topjohnwu/magisk/container/BaseModule.java @@ -1,8 +1,8 @@ package com.topjohnwu.magisk.container; - import android.content.ContentValues; import android.database.Cursor; +import android.text.TextUtils; import java.util.List; @@ -10,21 +10,27 @@ import androidx.annotation.NonNull; public abstract class BaseModule implements Comparable { - private String mId = null, mName, mVersion, mAuthor, mDescription; + private String mId, mName, mVersion, mAuthor, mDescription; private int mVersionCode = -1, minMagiskVersion = -1; - protected BaseModule() {} + protected BaseModule() { + mId = mName = mVersion = mAuthor = mDescription = ""; + } protected BaseModule(Cursor c) { - mId = c.getString(c.getColumnIndex("id")); - mName = c.getString(c.getColumnIndex("name")); - mVersion = c.getString(c.getColumnIndex("version")); + mId = nonNull(c.getString(c.getColumnIndex("id"))); + mName = nonNull(c.getString(c.getColumnIndex("name"))); + mVersion = nonNull(c.getString(c.getColumnIndex("version"))); mVersionCode = c.getInt(c.getColumnIndex("versionCode")); - mAuthor = c.getString(c.getColumnIndex("author")); - mDescription = c.getString(c.getColumnIndex("description")); + mAuthor = nonNull(c.getString(c.getColumnIndex("author"))); + mDescription = nonNull(c.getString(c.getColumnIndex("description"))); minMagiskVersion = c.getInt(c.getColumnIndex("minMagisk")); } + private String nonNull(String s) { + return s == null ? "" : s; + } + public ContentValues getContentValues() { ContentValues values = new ContentValues(); values.put("id", mId); diff --git a/app/src/full/java/com/topjohnwu/magisk/container/Repo.java b/app/src/full/java/com/topjohnwu/magisk/container/Repo.java index 48031cf84..853cb811e 100644 --- a/app/src/full/java/com/topjohnwu/magisk/container/Repo.java +++ b/app/src/full/java/com/topjohnwu/magisk/container/Repo.java @@ -2,6 +2,7 @@ package com.topjohnwu.magisk.container; import android.content.ContentValues; import android.database.Cursor; +import android.text.TextUtils; import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.utils.Download; @@ -35,7 +36,7 @@ public class Repo extends BaseModule { throw new IllegalRepoException("Repo [" + repoName + "] parse error: " + e.getMessage()); } - if (getId() == null) { + if (TextUtils.isEmpty(getId())) { throw new IllegalRepoException("Repo [" + repoName + "] does not contain id"); } if (getVersionCode() < 0) {