https://kotlinlang.org logo
#announcements
Title
# announcements
p

pawel.rybicki

09/03/2019, 3:55 PM
I got crash on prod and had to use 'allowedUrls?.forEach' even tho IDE tells me it is not necessary
m

Marko Mitic

09/03/2019, 3:56 PM
If superclass constructor is calling
setText
, allowedUrls won't be initialized in time
👍 5
👌 3
e

Eugen Martynov

09/03/2019, 3:57 PM
Actually good guess!
w

wasyl

09/03/2019, 3:58 PM
Yep, nice catch!
c

Casey Brooks

09/03/2019, 3:58 PM
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

streetsofboston

09/03/2019, 3:59 PM
And this is why folks complain about the poor API design (and implementation) of the Android Framework…..
p

pawel.rybicki

09/03/2019, 4:01 PM
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

wasyl

09/03/2019, 4:12 PM
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

pawel.rybicki

09/03/2019, 4:22 PM
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

Casey Brooks

09/03/2019, 4:31 PM
With that
?.let
call, it might be that the initial
textViewMessage
is null in the majority of cases
p

pawel.rybicki

09/03/2019, 4:35 PM
Then the crashing code would not execute at all