Skip to content

Commit fc997b4

Browse files
author
Gilles Debunne
committed
NPE in GMail / TextLine
Bug 5753061 https://android-git.corp.google.com/g/#/c/154756/1 revealed an other bug in SpanSet. The fitered (non empty) spans were added in their original position instead of being indexed by count. The nullation on recycle hence left null holes in the array. Change-Id: If5c1435cee9a2cb88a608aa8e5f4f2f23382154c
1 parent f0bbc49 commit fc997b4

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

core/java/android/text/TextLine.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ public void init(Spanned spanned, int start, int limit) {
886886
spanFlags = new int[length];
887887
}
888888

889-
int count = 0;
889+
numberOfSpans = 0;
890890
for (int i = 0; i < length; i++) {
891891
final E span = allSpans[i];
892892

@@ -896,14 +896,13 @@ public void init(Spanned spanned, int start, int limit) {
896896

897897
final int spanFlag = spanned.getSpanFlags(span);
898898

899-
spans[i] = span;
900-
spanStarts[i] = spanStart;
901-
spanEnds[i] = spanEnd;
902-
spanFlags[i] = spanFlag;
899+
spans[numberOfSpans] = span;
900+
spanStarts[numberOfSpans] = spanStart;
901+
spanEnds[numberOfSpans] = spanEnd;
902+
spanFlags[numberOfSpans] = spanFlag;
903903

904-
count++;
904+
numberOfSpans++;
905905
}
906-
numberOfSpans = count;
907906
}
908907

909908
public boolean hasSpansIntersecting(int start, int end) {
@@ -926,6 +925,7 @@ int getNextTransition(int start, int limit) {
926925
}
927926

928927
public void recycle() {
928+
// The spans array is guaranteed to be not null when numberOfSpans is > 0
929929
for (int i = 0; i < numberOfSpans; i++) {
930930
spans[i] = null; // prevent a leak: no reference kept when TextLine is recycled
931931
}

0 commit comments

Comments
 (0)