Skip to content

fix(android): setTextColor is non-nullable, prevent null exception#11147

Open
NathanWalker wants to merge 2 commits intomainfrom
fix/android-text-color-null-exception
Open

fix(android): setTextColor is non-nullable, prevent null exception#11147
NathanWalker wants to merge 2 commits intomainfrom
fix/android-text-color-null-exception

Conversation

@NathanWalker
Copy link
Copy Markdown
Contributor

@NathanWalker NathanWalker commented Mar 27, 2026

  • ensures that setTextColor method is only called with a defined value, preventing crashes based on timing/race

Prevents innocent app crash due to bindings update timing (often on page navigations):

Error: java.lang.NullPointerException
StackTrace:
  [color:setNative](file:///data/data/com.example.app/files/files/app/vendor.mjs)

This occurs because this.nativeTextViewProtected.setTextColor(value) is not nullable.
https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/core/java/android/widget/TextView.java#5602

@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Mar 27, 2026

View your CI Pipeline Execution ↗ for commit 9bc2fbf

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 3m 46s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-27 22:24:10 UTC

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents an Android crash in TextBase by ensuring setTextColor(...) isn’t invoked with a null/undefined value during timing/race conditions in bindings updates.

Changes:

  • Guarded the Android colorProperty.setNative path to avoid calling TextView.setTextColor(...) with an undefined value.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 415 to 416
} else if (value) {
this.nativeTextViewProtected.setTextColor(value);
Copy link

Copilot AI Mar 27, 2026

Choose a reason for hiding this comment

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

The new else if (value) guard avoids the NPE, but it relies on truthiness. To make the intent explicit and avoid accidentally skipping valid falsy values (and to document the actual runtime contract from the property system), consider checking specifically for null/undefined and updating the parameter type to include null | undefined.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Applied in 9bc2fbf — replaced else if (value) with else if (value != null) for an explicit null/undefined check, and updated the parameter type to Color | android.content.res.ColorStateList | null | undefined.

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.

4 participants