I got crash on prod and had to use 'allowedUrls?.f...
# announcements
p
I got crash on prod and had to use 'allowedUrls?.forEach' even tho IDE tells me it is not necessary
m
If superclass constructor is calling
setText
, allowedUrls won't be initialized in time
đź‘Ť 5
đź‘Ś 3
e
Actually good guess!
w
Yep, nice catch!
c
Yup, that's what going on. From the source of
TextView
base class:
Copy code
public TextView(
            Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);

        // TextView is important by default, unless app developer overrode attribute.
        if (getImportantForAutofill() == IMPORTANT_FOR_AUTOFILL_AUTO) {
            setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES);
        }

        setTextInternal(""); <-- THIS IS THE CRASH
s
And this is why folks complain about the poor API design (and implementation) of the Android Framework…..
p
Oh holy cow I would never expect that! I wonder why did this happen randomly on some textview? This is in recyclerview and worked for several days just fine, displaying bunch of textviews
Anyone?
w
I don’t think the problem is that
setTextInternal
, but there’s another
setText
call in the constructor. But maybe it’s only there on certain Android versions?
p
Nope it was for single user for different OSes, I could not spot the difference in content for this user but I guess smth must be differently there
c
With that
?.let
call, it might be that the initial
textViewMessage
is null in the majority of cases
p
Then the crashing code would not execute at all