Fix possible npe

This commit is contained in:
Chumva 2019-10-22 15:03:32 +03:00
parent c4aafe20cb
commit e35c7f5ead

View file

@ -76,20 +76,22 @@ public class WikivoyageWptPtMenuBuilder extends WptPtMenuBuilder {
} }
private HashMap<String, String> getDescriptionTokens(String desc, String... allowedKeys) { private HashMap<String, String> getDescriptionTokens(String desc, String... allowedKeys) {
String[] tokens = desc.split("\n");
HashMap<String, String> mTokens = new HashMap<>(); HashMap<String, String> mTokens = new HashMap<>();
for (String token : tokens) { if (!Algorithms.isEmpty(desc)) {
boolean matched = false; String[] tokens = desc.split("\n");
for (String key : allowedKeys) { for (String token : tokens) {
if (token.startsWith(key)) { boolean matched = false;
matched = true; for (String key : allowedKeys) {
String value = token.substring(key.length()).trim(); if (token.startsWith(key)) {
mTokens.put(key, value); matched = true;
String value = token.substring(key.length()).trim();
mTokens.put(key, value);
}
}
if (!matched) {
String s = mTokens.get(KEY_DESCRIPTION);
mTokens.put(KEY_DESCRIPTION, s != null ? s + "\n" + token : token);
} }
}
if (!matched) {
String s = mTokens.get(KEY_DESCRIPTION);
mTokens.put(KEY_DESCRIPTION, s != null ? s + "\n" + token : token);
} }
} }
return mTokens; return mTokens;