Skip to content

Commit

Permalink
Don't assume that list of styles hasn't changed in length
Browse files Browse the repository at this point in the history
This fixes a crash on missing styles in some circumstances.
  • Loading branch information
simonpoole committed Dec 31, 2024
1 parent 2a5393c commit 9062c58
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/main/java/de/blau/android/resources/DataStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -1420,8 +1420,6 @@ public String[] getStyleList(@NonNull Context context) {
addDefaultStyle(context);
}
// creating the default style object will set availableStyles
String[] res = new String[availableStyles.size()];
res[0] = BUILTIN_STYLE_NAME;
Map<String, DataStyle> sortedMap = new TreeMap<>();
for (Entry<String, DataStyle> entry : availableStyles.entrySet()) {
final DataStyle value = entry.getValue();
Expand All @@ -1432,15 +1430,12 @@ public String[] getStyleList(@NonNull Context context) {
Log.e(DEBUG_TAG, "Style object missing for style " + key);
}
}
String[] keys = sortedMap.keySet().toArray(new String[0]); // sort the list
int j = 1;
for (int i = 0; i < res.length; i++) {
if (!BUILTIN_STYLE_NAME.equals(keys[i])) {
res[j] = keys[i];
j++;
}
} // probably silly way of doing this
return res;
List<String> res = new ArrayList<>();
res.addAll(sortedMap.keySet());
if (!BUILTIN_STYLE_NAME.equals(res.get(0))) {
res.add(0, BUILTIN_STYLE_NAME);
}
return res.toArray(new String[0]);
}

/**
Expand Down

0 comments on commit 9062c58

Please sign in to comment.