Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bfdc4775 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Avoid NPE in trimToLengthWithEllipsis().

Currently, the text paramter is annotated with @Nullable
but passing a null value will cause an NPE.

Test: atest core/tests/coretests/src/android/text/TextUtilsTest.java
Change-Id: I95a71246aa0fe3398f09cb9b4b037ca096900ad4
parent 58686805
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2173,7 +2173,7 @@ public class TextUtils {
    public static <T extends CharSequence> T trimToLengthWithEllipsis(@Nullable T text,
            @IntRange(from = 1) int size) {
        T trimmed = trimToSize(text, size);
        if (trimmed.length() < text.length()) {
        if (text != null && trimmed.length() < text.length()) {
            trimmed = (T) (trimmed.toString() + "...");
        }
        return trimmed;
+1 −0
Original line number Diff line number Diff line
@@ -792,5 +792,6 @@ public class TextUtilsTest {
        assertEquals("ABC...", TextUtils.trimToLengthWithEllipsis("ABCDEF", 3));
        assertEquals("ABC", TextUtils.trimToLengthWithEllipsis("ABC", 3));
        assertEquals("", TextUtils.trimToLengthWithEllipsis("", 3));
        assertNull(TextUtils.trimToLengthWithEllipsis(null, 3));
    }
}