Skip to content

Fix: bounds-check drawer subtitle array access to prevent crash#557

Draft
djbclark wants to merge 1 commit into
SuperMonster003:masterfrom
djbclark:pr/drawer-crash-fix
Draft

Fix: bounds-check drawer subtitle array access to prevent crash#557
djbclark wants to merge 1 commit into
SuperMonster003:masterfrom
djbclark:pr/drawer-crash-fix

Conversation

@djbclark

Copy link
Copy Markdown

When a SharedPreference key stored for keep_screen_on_when_in_foreground does not match any entry in R.array.keys_keep_screen_on_when_in_foreground, indexOf() returns -1. The subsequent array access at that index throws ArrayIndexOutOfBoundsException, crashing DrawerFragment.onResume.

This is a pre-existing bug that any code path writing an unrecognized value to the preference can trigger (not just external callers — even a fresh install picking up a default that doesn't match the keys array could hit it).

Fix: Add a bounds check (if (i in keys.indices)) before the array access, showing no subtitle when the key isn't found. This guards the single affected refreshSubtitle override in DrawerFragment.

One file changed, 7 lines added.

Thank you again for your work on AutoJs6!

DrawerFragment.refreshSubtitle crashes with
ArrayIndexOutOfBoundsException when Pref.keyKeepScreenOnWhenInForeground
returns a value not in R.array.keys_keep_screen_on_when_in_foreground
(e.g. after a fleet profile write). Guard with keys.indices check and
show null subtitle instead of crashing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant