Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent crash when setting underlineColorAndroid #24183

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.TextView;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.JSApplicationIllegalArgumentException;
import com.facebook.react.bridge.ReactContext;
Expand Down Expand Up @@ -64,7 +65,7 @@
*/
@ReactModule(name = ReactTextInputManager.REACT_CLASS)
public class ReactTextInputManager extends BaseViewManager<ReactEditText, LayoutShadowNode> {

public static final String TAG = ReactTextInputManager.class.getSimpleName();
protected static final String REACT_CLASS = "AndroidTextInput";

private static final int[] SPACING_TYPES = {
Expand Down Expand Up @@ -464,9 +465,14 @@ public void setUnderlineColor(ReactEditText view, @Nullable Integer underlineCol
// Drawable.mutate() can sometimes crash due to an AOSP bug:
// See https://code.google.com/p/android/issues/detail?id=191754 for more info
Drawable background = view.getBackground();
Drawable drawableToMutate = background.getConstantState() != null ?
background.mutate() :
background;
Drawable drawableToMutate = background;
if (background.getConstantState() != null) {
try {
drawableToMutate = background.mutate();
} catch (NullPointerException e) {
FLog.e(TAG, "NullPointerException when setting underlineColorAndroid for TextInput", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class doesn't have a TAG field. Did you test this change? Would you mind fixing it up, testing it and then updating the PR? Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I just added the missing tag. RNTester build passed but I can not start the packager due to #23936.

}
}

if (underlineColor == null) {
drawableToMutate.clearColorFilter();
Expand Down