fix(android): setTextColor is non-nullable, prevent null exception#11147
fix(android): setTextColor is non-nullable, prevent null exception#11147NathanWalker wants to merge 2 commits intomainfrom
Conversation
|
View your CI Pipeline Execution ↗ for commit 9bc2fbf
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
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.setNativepath to avoid callingTextView.setTextColor(...)with an undefined value.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } else if (value) { | ||
| this.nativeTextViewProtected.setTextColor(value); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
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.
…lorProperty.setNative Agent-Logs-Url: https://github.com/NativeScript/NativeScript/sessions/bb1580df-8f26-4e42-85b4-2c73c1bc54bc Co-authored-by: NathanWalker <[email protected]>
setTextColormethod is only called with a defined value, preventing crashes based on timing/racePrevents innocent app crash due to bindings update timing (often on page navigations):
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