From d5ea4b4b800a13057ae69bdeb367046e217630c9 Mon Sep 17 00:00:00 2001 From: Ryan Meredith Date: Fri, 21 Aug 2020 11:09:24 -0400 Subject: [PATCH] Android: Prevent getSetting ClassCastExceptions in ItemViews --- .../features/settings/model/view/CheckBoxSetting.java | 4 ++-- .../features/settings/model/view/FilePicker.java | 5 ++--- .../settings/model/view/InputBindingSetting.java | 4 ++-- .../settings/model/view/RumbleBindingSetting.java | 2 +- .../settings/model/view/SingleChoiceSetting.java | 10 +++++----- .../view/SingleChoiceSettingDynamicDescriptions.java | 10 +++++----- .../features/settings/model/view/SliderSetting.java | 4 ++-- .../settings/model/view/StringSingleChoiceSetting.java | 10 +++++----- 8 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/CheckBoxSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/CheckBoxSetting.java index 9deea6d8b1..38af32be9d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/CheckBoxSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/CheckBoxSetting.java @@ -16,7 +16,7 @@ public final class CheckBoxSetting extends SettingsItem public boolean isChecked() { - if (getSetting() == null) + if (getSetting() == null || !(getSetting() instanceof BooleanSetting)) { return mDefaultValue; } @@ -34,7 +34,7 @@ public final class CheckBoxSetting extends SettingsItem */ public BooleanSetting setChecked(boolean checked) { - if (getSetting() == null) + if (getSetting() == null || !(getSetting() instanceof BooleanSetting)) { BooleanSetting setting = new BooleanSetting(getKey(), getSection(), checked); setSetting(setting); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/FilePicker.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/FilePicker.java index ad9456a9cc..4901795e88 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/FilePicker.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/FilePicker.java @@ -25,14 +25,13 @@ public final class FilePicker extends SettingsItem public String getSelectedValue() { - StringSetting setting = (StringSetting) getSetting(); - - if (setting == null) + if (getSetting() == null || !(getSetting() instanceof StringSetting)) { return mDefaultValue; } else { + StringSetting setting = (StringSetting) getSetting(); return setting.getValue(); } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/InputBindingSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/InputBindingSetting.java index 03b23bf328..b762539d1a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/InputBindingSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/InputBindingSetting.java @@ -22,7 +22,7 @@ public class InputBindingSetting extends SettingsItem public String getValue() { - if (getSetting() == null) + if (getSetting() == null || !(getSetting() instanceof StringSetting)) { return ""; } @@ -78,7 +78,7 @@ public class InputBindingSetting extends SettingsItem editor.putString(getKey() + gameId, ui); editor.apply(); - if (getSetting() == null) + if (getSetting() == null || !(getSetting() instanceof StringSetting)) { StringSetting setting = new StringSetting(getKey(), getSection(), bind); setSetting(setting); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/RumbleBindingSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/RumbleBindingSetting.java index 883a33f8bd..5d658a7205 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/RumbleBindingSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/RumbleBindingSetting.java @@ -22,7 +22,7 @@ public class RumbleBindingSetting extends InputBindingSetting @Override public String getValue() { - if (getSetting() == null) + if (getSetting() == null || !(getSetting() instanceof StringSetting)) { return ""; } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SingleChoiceSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SingleChoiceSetting.java index 0edfd8f36b..52c2337ea2 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SingleChoiceSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SingleChoiceSetting.java @@ -40,14 +40,14 @@ public final class SingleChoiceSetting extends SettingsItem public int getSelectedValue() { - if (getSetting() != null) + if (getSetting() == null || !(getSetting() instanceof IntSetting)) { - IntSetting setting = (IntSetting) getSetting(); - return setting.getValue(); + return mDefaultValue; } else { - return mDefaultValue; + IntSetting setting = (IntSetting) getSetting(); + return setting.getValue(); } } @@ -65,7 +65,7 @@ public final class SingleChoiceSetting extends SettingsItem */ public IntSetting setSelectedValue(int selection) { - if (getSetting() == null) + if (getSetting() == null || !(getSetting() instanceof IntSetting)) { IntSetting setting = new IntSetting(getKey(), getSection(), selection); setSetting(setting); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SingleChoiceSettingDynamicDescriptions.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SingleChoiceSettingDynamicDescriptions.java index b5d6e605b6..0f31a89088 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SingleChoiceSettingDynamicDescriptions.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SingleChoiceSettingDynamicDescriptions.java @@ -59,14 +59,14 @@ public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem public int getSelectedValue() { - if (getSetting() != null) + if (getSetting() == null || !(getSetting() instanceof IntSetting)) { - IntSetting setting = (IntSetting) getSetting(); - return setting.getValue(); + return mDefaultValue; } else { - return mDefaultValue; + IntSetting setting = (IntSetting) getSetting(); + return setting.getValue(); } } @@ -84,7 +84,7 @@ public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem */ public IntSetting setSelectedValue(int selection) { - if (getSetting() == null) + if (getSetting() == null || !(getSetting() instanceof IntSetting)) { IntSetting setting = new IntSetting(getKey(), getSection(), selection); setSetting(setting); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SliderSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SliderSetting.java index f0209a7b33..93c55724a6 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SliderSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/SliderSetting.java @@ -75,7 +75,7 @@ public final class SliderSetting extends SettingsItem */ public IntSetting setSelectedValue(int selection) { - if (getSetting() == null) + if (getSetting() == null || !(getSetting() instanceof IntSetting)) { IntSetting setting = new IntSetting(getKey(), getSection(), selection); setSetting(setting); @@ -98,7 +98,7 @@ public final class SliderSetting extends SettingsItem */ public FloatSetting setSelectedValue(float selection) { - if (getSetting() == null) + if (getSetting() == null || !(getSetting() instanceof FloatSetting)) { FloatSetting setting = new FloatSetting(getKey(), getSection(), selection); setSetting(setting); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/StringSingleChoiceSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/StringSingleChoiceSetting.java index b2ff1546a5..0dac6311c7 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/StringSingleChoiceSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/view/StringSingleChoiceSetting.java @@ -71,14 +71,14 @@ public class StringSingleChoiceSetting extends SettingsItem public String getSelectedValue() { - if (getSetting() != null) + if (getSetting() == null || !(getSetting() instanceof StringSetting)) { - StringSetting setting = (StringSetting) getSetting(); - return setting.getValue(); + return mDefaultValue; } else { - return mDefaultValue; + StringSetting setting = (StringSetting) getSetting(); + return setting.getValue(); } } @@ -110,7 +110,7 @@ public class StringSingleChoiceSetting extends SettingsItem */ public StringSetting setSelectedValue(String selection) { - if (getSetting() == null) + if (getSetting() == null || !(getSetting() instanceof StringSetting)) { StringSetting setting = new StringSetting(getKey(), getSection(), selection); setSetting(setting);