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
This commit is contained in:
Quang Luong
2019-04-01 18:55:29 -07:00
parent dd07ae579c
commit abe10b3e62

View File

@@ -28,7 +28,6 @@ import com.android.internal.annotations.VisibleForTesting;
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 @@ public class StateMachine {
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;