aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorDocile-Alligator <chineseperson5@gmail.com>2022-04-23 13:36:25 +0000
committerDocile-Alligator <chineseperson5@gmail.com>2022-04-23 13:36:25 +0000
commit3fa86984dce075f7646bdc6a83abf062c007c2aa (patch)
treee7bfd3c18f326213f60cf4e14f76fcfbebd72757 /app/src/main
parent05e9b8b36e1625a23e96f0205f7a8d92be485b99 (diff)
downloadinfinity-for-reddit-3fa86984dce075f7646bdc6a83abf062c007c2aa.tar
infinity-for-reddit-3fa86984dce075f7646bdc6a83abf062c007c2aa.tar.gz
infinity-for-reddit-3fa86984dce075f7646bdc6a83abf062c007c2aa.tar.bz2
infinity-for-reddit-3fa86984dce075f7646bdc6a83abf062c007c2aa.tar.lz
infinity-for-reddit-3fa86984dce075f7646bdc6a83abf062c007c2aa.tar.xz
infinity-for-reddit-3fa86984dce075f7646bdc6a83abf062c007c2aa.tar.zst
infinity-for-reddit-3fa86984dce075f7646bdc6a83abf062c007c2aa.zip
Fix NullPointerException in Utils.parseInlineEmotes.
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java46
1 files changed, 24 insertions, 22 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
index 604188b8..7a4c584a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
@@ -190,30 +190,32 @@ public final class Utils {
public static String parseInlineEmotes(String markdown, JSONObject mediaMetadataObject) throws JSONException {
JSONArray mediaMetadataNames = mediaMetadataObject.names();
- for (int i = 0; i < mediaMetadataNames.length(); i++) {
- if (!mediaMetadataNames.isNull(i)) {
- String mediaMetadataKey = mediaMetadataNames.getString(i);
- if (mediaMetadataObject.isNull(mediaMetadataKey)) {
- continue;
- }
- JSONObject item = mediaMetadataObject.getJSONObject(mediaMetadataKey);
- if (item.isNull(JSONUtils.STATUS_KEY)
- || !item.getString(JSONUtils.STATUS_KEY).equals("valid")
- || item.isNull(JSONUtils.ID_KEY)
- || item.isNull(JSONUtils.T_KEY)
- || item.isNull(JSONUtils.S_KEY)) {
- continue;
- }
- String emote_type = item.getString(JSONUtils.T_KEY);
- String emote_id = item.getString(JSONUtils.ID_KEY);
+ if (mediaMetadataNames != null) {
+ for (int i = 0; i < mediaMetadataNames.length(); i++) {
+ if (!mediaMetadataNames.isNull(i)) {
+ String mediaMetadataKey = mediaMetadataNames.getString(i);
+ if (mediaMetadataObject.isNull(mediaMetadataKey)) {
+ continue;
+ }
+ JSONObject item = mediaMetadataObject.getJSONObject(mediaMetadataKey);
+ if (item.isNull(JSONUtils.STATUS_KEY)
+ || !item.getString(JSONUtils.STATUS_KEY).equals("valid")
+ || item.isNull(JSONUtils.ID_KEY)
+ || item.isNull(JSONUtils.T_KEY)
+ || item.isNull(JSONUtils.S_KEY)) {
+ continue;
+ }
+ String emote_type = item.getString(JSONUtils.T_KEY);
+ String emote_id = item.getString(JSONUtils.ID_KEY);
- JSONObject s_key = item.getJSONObject(JSONUtils.S_KEY);
- if (s_key.isNull(JSONUtils.U_KEY)) {
- continue;
- }
- String emote_url = s_key.getString(JSONUtils.U_KEY);
+ JSONObject s_key = item.getJSONObject(JSONUtils.S_KEY);
+ if (s_key.isNull(JSONUtils.U_KEY)) {
+ continue;
+ }
+ String emote_url = s_key.getString(JSONUtils.U_KEY);
- markdown = markdown.replace("![img](" + emote_id + ")", "[" + emote_type + "](" + emote_url + ") ");
+ markdown = markdown.replace("![img](" + emote_id + ")", "[" + emote_type + "](" + emote_url + ") ");
+ }
}
}
return markdown;