SpannableStringBuilder append() NullPointerException

365 Views Asked by At
// Documentation from interface
public SpannableStringBuilder append(CharSequence text) {
    int length = length();
    return replace(length, length, text, 0, text.length());
}

SpannableStringBuilder source code append() function doesn't avoid NullPointerException?? If text is null, append() function definitely throw NullPointerException. It's easily be forgotten to check every case if text is null. For example the text may from the server. Anyone has a better idea for SpannableStringBuilder append() function to avoid npe?

1

There are 1 best solutions below

0
On

You could wrap the SpannableStringBuilder in your own class and put the null check there .