Merge "Fix for out-of-bound error regarding NoCopySpan objects" into tm-dev
diff --git a/core/java/android/view/accessibility/AccessibilityNodeInfo.java b/core/java/android/view/accessibility/AccessibilityNodeInfo.java
index 4baad1e..a20b2b2 100644
--- a/core/java/android/view/accessibility/AccessibilityNodeInfo.java
+++ b/core/java/android/view/accessibility/AccessibilityNodeInfo.java
@@ -3046,6 +3046,9 @@
             int spanToReplaceStart = spannable.getSpanStart(span);
             int spanToReplaceEnd = spannable.getSpanEnd(span);
             int spanToReplaceFlags = spannable.getSpanFlags(span);
+            if (spanToReplaceStart < 0) {
+                continue;
+            }
             spannable.removeSpan(span);
             ClickableSpan replacementSpan = (span instanceof URLSpan)
                     ? new AccessibilityURLSpan((URLSpan) span)
@@ -3083,6 +3086,9 @@
             int spanToReplaceStart = spannable.getSpanStart(span);
             int spanToReplaceEnd = spannable.getSpanEnd(span);
             int spanToReplaceFlags = spannable.getSpanFlags(span);
+            if (spanToReplaceStart < 0) {
+                continue;
+            }
             spannable.removeSpan(span);
             ReplacementSpan replacementSpan = new AccessibilityReplacementSpan(replacementText);
             spannable.setSpan(replacementSpan, spanToReplaceStart, spanToReplaceEnd,