Obsolete
Status Update
Comments
ko...@gmail.com <ko...@gmail.com> #2
I have the same problem on my HTC flyer(android 3.x)
when mixing "left to right" with "right to left", then sometimes cause StringIndexOutOfBoundsException.
my stacktrace like this
java.lang.StringIndexOutOfBoundsException: start=20 end=13 buffer.length=26 index=0 length=22
at java.lang.String.getChars(String.java:943)
at android.text.SpannableStringInternal.getChars(SpannableStringInternal.java:70)
at android.text.TextUtils.getChars(TextUtils.java:66)
at android.text.TextLine.set(TextLine.java:141)
at android.text.Layout.draw(Layout.java:390)
at android.widget.TextView.onDraw(TextView.java:4675)
when mixing "left to right" with "right to left", then sometimes cause StringIndexOutOfBoundsException.
my stacktrace like this
java.lang.StringIndexOutOfBoundsException: start=20 end=13 buffer.length=26 index=0 length=22
at java.lang.String.getChars(String.java:943)
at android.text.SpannableStringInternal.getChars(SpannableStringInternal.java:70)
at android.text.TextUtils.getChars(TextUtils.java:66)
at android.text.TextLine.set(TextLine.java:141)
at android.text.Layout.draw(Layout.java:390)
at android.widget.TextView.onDraw(TextView.java:4675)
dm...@gmail.com <dm...@gmail.com> #3
to reproduce incorrect mLines generation please create StaticLayout with
width = 532
align = ALIGN_NORMAL
source =
"Gshsh jdjd jd. Fj bjjdjr jfjf. Fjfjrhfjrjrj jfjrhrururjrjr urjrb hdjdjr jrjrjr jfjfj hdhdj jdjjff hdhdhdhgjfjf. Hdhd. hdjdjdhdbdhfjfjf"
where are 0xE401 symbols that are replaced by ImageSpans with size of 64
this will produce the following mLines:
mLines (id=830032126608)
[0] 1073741824 [0x40000000]
[1] 0 [0x0] [^@ (NUL)]
[2] 8 [0x8] [^H (BS)]
[3] 1073741856 [0x40000020]
[4] 42 [0x2a] [*]
[5] 8 [0x8] [^H (BS)]
[6] 1073741870 [0x4000002e]
[7] 80 [0x50] [P]
[8] 8 [0x8] [^H (BS)]
[9] 1073741912 [0x40000058]
[10] 118 [0x76] [v]
[11] 8 [0x8] [^H (BS)]
[12] 1073741892 [0x40000044]
[13] 156 [0x9c] [^Ü]
[14] 8 [0x8] [^H (BS)]
[15] 1073741925 [0x40000065]
[16] 194 [0xc2] [Â]
[17] 8 [0x8] [^H (BS)]
[18] 1073741956 [0x40000084]
[19] 232 [0xe8] [è]
[20] 9 [0x9] [^I (TAB)]
[21] 150 [0x96] [^Ö]
[22] 290 [0x122] [Ģ]
[23] 0 [0x0] [^@ (NUL)]
[24] 0 [0x0] [^@ (NUL)]
[25] 0 [0x0] [^@ (NUL)]
[26] 0 [0x0] [^@ (NUL)]
[27] 0 [0x0] [^@ (NUL)]
[28] 0 [0x0] [^@ (NUL)]
-- line 3 has an offset 0x58, line 4 has an offset 0x44.
this would not crash because of English, but the layout is wrong.
such incorrectly calculated layout would crash for Arabic when TextLine.set would call TextUtils.getChars
width = 532
align = ALIGN_NORMAL
source =
"Gshsh jdjd jd. Fj bjjdjr jfjf. Fjfjrhfjrjrj jfjrhrururjrjr urjrb hdjdjr jrjrjr jfjfj hdhdj jdjjff hdhdhdhgjfjf. Hdhd. hdjdjdhdbdhfjfjf"
where are 0xE401 symbols that are replaced by ImageSpans with size of 64
this will produce the following mLines:
mLines (id=830032126608)
[0] 1073741824 [0x40000000]
[1] 0 [0x0] [^@ (NUL)]
[2] 8 [0x8] [^H (BS)]
[3] 1073741856 [0x40000020]
[4] 42 [0x2a] [*]
[5] 8 [0x8] [^H (BS)]
[6] 1073741870 [0x4000002e]
[7] 80 [0x50] [P]
[8] 8 [0x8] [^H (BS)]
[9] 1073741912 [0x40000058]
[10] 118 [0x76] [v]
[11] 8 [0x8] [^H (BS)]
[12] 1073741892 [0x40000044]
[13] 156 [0x9c] [^Ü]
[14] 8 [0x8] [^H (BS)]
[15] 1073741925 [0x40000065]
[16] 194 [0xc2] [Â]
[17] 8 [0x8] [^H (BS)]
[18] 1073741956 [0x40000084]
[19] 232 [0xe8] [è]
[20] 9 [0x9] [^I (TAB)]
[21] 150 [0x96] [^Ö]
[22] 290 [0x122] [Ģ]
[23] 0 [0x0] [^@ (NUL)]
[24] 0 [0x0] [^@ (NUL)]
[25] 0 [0x0] [^@ (NUL)]
[26] 0 [0x0] [^@ (NUL)]
[27] 0 [0x0] [^@ (NUL)]
[28] 0 [0x0] [^@ (NUL)]
-- line 3 has an offset 0x58, line 4 has an offset 0x44.
this would not crash because of English, but the layout is wrong.
such incorrectly calculated layout would crash for Arabic when TextLine.set would call TextUtils.getChars
fa...@android.com <fa...@android.com> #4
@Dmitri, could you attach a bugreport. I need to see the Android version and some other infos.
fa...@android.com <fa...@android.com> #5
Can you also give the exact code you are using for repro?
fa...@android.com <fa...@android.com> #6
Cannot repro on ICS (4.0.4 / IML76I). I am suspecting you are using a "pre ICS" version (Gingerbread for example ?)
dm...@gmail.com <dm...@gmail.com> #7
the attached bugreport is for slightly different string that I had in the initial post, but the crash place is the same:
06-04 18:00:18.302 1063 1063 E AndroidRuntime: java.lang.StringIndexOutOfBoundsException: length=122; regionStart=117; regionLength=-6
06-04 18:00:18.302 1063 1063 E AndroidRuntime: at java.lang.String.startEndAndLength(String.java:593)
06-04 18:00:18.302 1063 1063 E AndroidRuntime: at java.lang.String.getChars(String.java:902)
06-04 18:00:18.302 1063 1063 E AndroidRuntime: at android.text.SpannableStringInternal.getChars(SpannableStringInternal.java:70)
06-04 18:00:18.302 1063 1063 E AndroidRuntime: at android.text.TextUtils.getChars(TextUtils.java:70)
06-04 18:00:18.302 1063 1063 E AndroidRuntime: at android.text.TextLine.set(TextLine.java:150)
06-04 18:00:18.302 1063 1063 E AndroidRuntime: at android.text.Layout.draw(Layout.java:424)
06-04 18:00:18.302 1063 1063 E AndroidRuntime: java.lang.StringIndexOutOfBoundsException: length=122; regionStart=117; regionLength=-6
06-04 18:00:18.302 1063 1063 E AndroidRuntime: at java.lang.String.startEndAndLength(String.java:593)
06-04 18:00:18.302 1063 1063 E AndroidRuntime: at java.lang.String.getChars(String.java:902)
06-04 18:00:18.302 1063 1063 E AndroidRuntime: at android.text.SpannableStringInternal.getChars(SpannableStringInternal.java:70)
06-04 18:00:18.302 1063 1063 E AndroidRuntime: at android.text.TextUtils.getChars(TextUtils.java:70)
06-04 18:00:18.302 1063 1063 E AndroidRuntime: at android.text.TextLine.set(TextLine.java:150)
06-04 18:00:18.302 1063 1063 E AndroidRuntime: at android.text.Layout.draw(Layout.java:424)
ko...@gmail.com <ko...@gmail.com> #8
Hi
This is my error report and sample project
the String content is no meaning, I just want to reproduce my error.
On my galaxy nexus 4.0.2 and emulator 4.0 api level 14 (WVGA800) will crash.
If remove line 73(imagespans), then it works.
This is my error report and sample project
the String content is no meaning, I just want to reproduce my error.
On my galaxy nexus 4.0.2 and emulator 4.0 api level 14 (WVGA800) will crash.
If remove line 73(imagespans), then it works.
dm...@gmail.com <dm...@gmail.com> #9
updated to 4.0.4; was not able to reproduce.
(before was testing 4.0.2)
(before was testing 4.0.2)
ko...@gmail.com <ko...@gmail.com> #10
My sample code still crash my emulator when i change to 4.0.3 level 15(WVGA800)
Flyer 3.2.1 will crash too(need to change the TextView's content)
Is there any work around to avoid this if I still want imagespan in TextView?
Flyer 3.2.1 will crash too(need to change the TextView's content)
Is there any work around to avoid this if I still want imagespan in TextView?
dm...@gmail.com <dm...@gmail.com> #11
the workaround i found was to extend TextView; extend Spannable.Factory; set my spannable factory to TextView; this spannable factory creates spannable that delegates all methods to SpannableString, but getChars (in getChars i check if start < end); override TextView.setText where i call super.setText(text, TextView.BufferType.SPANNABLE) if ((Build.VERSION.SDK_INT >= 11) && (text instanceof Spanned))
cr...@gmail.com <cr...@gmail.com> #12
Hello Dimitri,
is there any news regarding this issue ? i think i have the exact same bug on my app.
Would you care to post the code which you extended textview ?
Thanks
is there any news regarding this issue ? i think i have the exact same bug on my app.
Would you care to post the code which you extended textview ?
Thanks
ap...@gmail.com <ap...@gmail.com> #13
I got this issue too. Thanks in advance.
cr...@gmail.com <cr...@gmail.com> #14
Sorry dude.
No one posted code - I couldn't find a solution so I just found another way to do what i wanted without using spannable ...
No one posted code - I couldn't find a solution so I just found another way to do what i wanted without using spannable ...
sa...@google.com <sa...@google.com> #15
Thank you for your feedback. We have tried our best to address the issue reported, however our product team has shifted work priority which doesn't include this issue. For now, we will be closing the issue as "Won't Fix (Obsolete)". If this issue still currently exists, we request that you log a new issue along with the latest bug report here: https://goo.gl/TbMiIO and reference this bug for context.
Description
at java.lang.String.startEndAndLength(String.java:593)
at java.lang.String.getChars(String.java:902)
at android.text.SpannableStringInternal.getChars(SpannableStringInternal.java:70)
at android.text.TextUtils.getChars(TextUtils.java:70)
at android.text.TextLine.set(TextLine.java:160)
at android.text.Layout.draw(Layout.java:424)
at android.widget.TextView.onDraw(TextView.java:5038)
It appears that StaticLayout calculates (StaticLayout.generate) the lines (mLines member) such that next line can have position less than previous. (there are ImageSpans in source CharSequence)
This causes crash in Layout.draw for arabic.
Layout.draw calls TextLine.set with start > end.
TextLine.set calls TextUtils.getChars with start > limit
For arabic TextLine.set (called from Layout.draw) would call TextUtils.getChars because (directions != Layout.DIRS_ALL_LEFT_TO_RIGHT) is true
For english TextLine.set (called from Layout.draw) would not call TextUtils.getChars for negative string because hasReplacement would be false
I guess the same applies to DynamicLayout because it uses StaticLayout internally