Skip to content

Commit b8c50e8

Browse files
committed
Text layout in switch may be null when accessibility events are fired.
1. The layout containing the text of a Switch is initialized on measure and if an accessibility event is fired before that then a NPE happens. bug:7169419 Change-Id: Iee3c01ca9157d14d228c4ff33c0810507e0e25a7
1 parent 494ac35 commit b8c50e8

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

core/java/android/widget/Switch.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,9 @@ public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
508508
@Override
509509
public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
510510
super.onPopulateAccessibilityEvent(event);
511-
CharSequence text = isChecked() ? mOnLayout.getText() : mOffLayout.getText();
512-
if (!TextUtils.isEmpty(text)) {
513-
event.getText().add(text);
511+
Layout layout = isChecked() ? mOnLayout : mOffLayout;
512+
if (layout != null && !TextUtils.isEmpty(layout.getText())) {
513+
event.getText().add(layout.getText());
514514
}
515515
}
516516

0 commit comments

Comments
 (0)