summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorJonathan Hamilton <jtrhamilton@gmail.com>2017-09-07 09:50:27 -0700
committerJonathan Hamilton <jtrhamilton@gmail.com>2017-09-08 10:06:53 -0700
commit221462808d96239bbfa7f862978a8b2846911d5b (patch)
tree605d8e640d2559bfdd9d01310c17865146d9b539 /Source/Android/app/src/main/java
parentce670c18519b30a10e17ab1f33193fcc11588da1 (diff)
Avoid crashes due to null SettingsSections
If a SettingsFile had at least one section, it was assumed all sections were correctly filled out. This caused crashes when opening the settings menus if that was not the case - for example the GFX.ini settings empty sections are removed by the main dolphin app, putting the .ini file in a state that would crash the settings window if at least one setting was changed in it from the default, some sections were left as default. This adds a subclass of HashMap<String, SettingSection> that constructs a new SettingSection instead of returning 'null' if the key isn't found, so the mSettings.get(FILE).get(SECTION).get(SETTING) pattern can be safely used.
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/SettingsFile.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/SettingsFile.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/SettingsFile.java
index 96f40c3296..dd4bbdfb66 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/SettingsFile.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/SettingsFile.java
@@ -23,6 +23,32 @@ import java.util.Set;
import java.util.TreeSet;
/**
+ * A HashMap<String, SettingSection> that constructs a new SettingSection instead of returning null
+ * when getting a key not already in the map
+ */
+final class SettingsSectionMap extends HashMap<String, SettingSection>
+{
+ @Override
+ public SettingSection get(Object key)
+ {
+ if (!(key instanceof String))
+ {
+ return null;
+ }
+
+ String stringKey = (String)key;
+
+ if (!super.containsKey(stringKey))
+ {
+ SettingSection section = new SettingSection(stringKey);
+ super.put(stringKey, section);
+ return section;
+ }
+ return super.get(key);
+ }
+}
+
+/**
* Contains static methods for interacting with .ini files in which settings are stored.
*/
public final class SettingsFile
@@ -256,7 +282,7 @@ public final class SettingsFile
*/
public static HashMap<String, SettingSection> readFile(final String fileName, SettingsActivityView view)
{
- HashMap<String, SettingSection> sections = new HashMap<>();
+ HashMap<String, SettingSection> sections = new SettingsSectionMap();
File ini = getSettingsFile(fileName);