summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoah Stanford <noah@livio.io>2021-12-07 16:51:25 -0500
committerNoah Stanford <noah@livio.io>2021-12-07 16:51:25 -0500
commit2445b371ccee2ba4afb5019a54e7e45649ae1d51 (patch)
tree3c2738bdcd2846c44e185827185e0a2a40ad0e29
parent423836c27a105ba521da32fdc060092aef88c66b (diff)
downloadsdl_android-2445b371ccee2ba4afb5019a54e7e45649ae1d51.tar.gz
Resolve #1774
Make SoftButtonObject throw IllegalStateException when given empty state list
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonObject.java8
1 files changed, 7 insertions, 1 deletions
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonObject.java b/base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonObject.java
index 76301bc07..4a8116d54 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonObject.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/SoftButtonObject.java
@@ -73,6 +73,8 @@ public class SoftButtonObject implements Cloneable{
*/
public SoftButtonObject(@NonNull String name, @NonNull List<SoftButtonState> states, @NonNull String initialStateName, OnEventListener onEventListener) {
+ setStates(states);
+
// Make sure there aren't two states with the same name
if (hasTwoStatesOfSameName(states)) {
DebugTool.logError(TAG, "Two states have the same name in states list for soft button object");
@@ -80,7 +82,6 @@ public class SoftButtonObject implements Cloneable{
}
this.name = name;
- this.states = states;
this.currentStateName = initialStateName;
this.buttonId = SOFT_BUTTON_ID_NOT_SET_VALUE;
this.onEventListener = onEventListener;
@@ -264,6 +265,11 @@ public class SoftButtonObject implements Cloneable{
* @param states a list of the object's soft button states. <strong>states should be unique for every SoftButtonObject. A SoftButtonState instance cannot be reused for multiple SoftButtonObjects.</strong>
*/
public void setStates(@NonNull List<SoftButtonState> states) {
+ // Make sure the list of states is not empty
+ if (states.isEmpty()) {
+ throw new IllegalStateException("The state list is empty");
+ }
+
this.states = states;
}