From 4c8ad6eb6241a0f689e49237ecadb65e8ffa4b6c Mon Sep 17 00:00:00 2001 From: Brian Muramatsu Date: Thu, 27 Jan 2011 18:13:39 -0800 Subject: [PATCH] Fix TextUtils#commaEllipsize Bug 3400770 TextUtils#commaEllipsize creates a MeasuredText "mt" object with the text to be ellipsized. It calls setPara which initializes mt's mPos member to be 0. It then calls addStyleRun which moves mPos to the end of the string. The loop back in commaEllipsize then calls mt addStyleRun again and this causes IndexOutOfBoundsException, because the paint object is trying to measure text past the text's length. It seems this was a typo and that the tempMt variable should be used, because the code is trying to measure the format string...not the the string to be ellipsized. This makes the saner parts of CTS test for this method pass now. Change-Id: Ib6aa6e4bbd6afff4c95ad4c4d51a384cc1389875 --- core/java/android/text/TextUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java index 774826510ba77..d5010c64f6a7e 100644 --- a/core/java/android/text/TextUtils.java +++ b/core/java/android/text/TextUtils.java @@ -1142,7 +1142,7 @@ public class TextUtils { // XXX this is probably ok, but need to look at it more tempMt.setPara(format, 0, format.length(), request); - float moreWid = mt.addStyleRun(p, mt.mLen, null); + float moreWid = tempMt.addStyleRun(p, tempMt.mLen, null); if (w + moreWid <= avail) { ok = i + 1;