Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Fix crash in EditText#getText
Browse files Browse the repository at this point in the history
The fact that View's constructor may call other methods before the
TextView constructor has a chance to initialize values means that
getText() may return null in the rare case where it is called
before the constructor.

Protect getText() from running into errors when the text is null,
as it just means the value is not ready yet.

Bug: 71638589
Test: CTS in topic
Change-Id: Ie11233416385353f78e3ee27fb0d3ec9b671512f
  • Loading branch information
Clara Bayarri committed Jan 18, 2018
1 parent 7d0e1f8 commit b102cc2
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/java/android/widget/EditText.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ protected MovementMethod getDefaultMovementMethod() {
@Override
public Editable getText() {
CharSequence text = super.getText();
// This can only happen during construction.
if (text == null) {
return null;
}
if (text instanceof Editable) {
return (Editable) super.getText();
}
Expand Down

0 comments on commit b102cc2

Please sign in to comment.