Catch ArrayIndexOutOfBoundsException in StateMachine.toString()
StateMachine.toString() calls mSmHandler.getCurrentState(). In the
rare case when mStateStackTopIndex is -1 due to the StateMachine being
not yet initalized, this results in an ArrayIndexOutOfBoundsException.
Bug: 124858416
Test: none
Change-Id: Id558be95b6e12d8a923d325bca5f6f6d7f942b22
diff --git a/core/java/com/android/internal/util/StateMachine.java b/core/java/com/android/internal/util/StateMachine.java
index dacdae6..6c217e5 100644
--- a/core/java/com/android/internal/util/StateMachine.java
+++ b/core/java/com/android/internal/util/StateMachine.java
@@ -28,7 +28,6 @@
import java.io.FileDescriptor;
import java.io.PrintWriter;
-import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
@@ -2102,7 +2101,7 @@
try {
name = mName.toString();
state = mSmHandler.getCurrentState().getName().toString();
- } catch (NullPointerException npe) {
+ } catch (NullPointerException | ArrayIndexOutOfBoundsException e) {
// Will use default(s) initialized above.
}
return "name=" + name + " state=" + state;