title: StringIndexOutOfBoundsException from SpannableStringInternal
body: <p>I keep recieving the following bug reports from the market:</p>
  
  <pre><code>java.lang.StringIndexOutOfBoundsException: length=51; regionStart=37; regionLength=-15 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:5262) at
  android.view.View.draw(View.java:11184) at
  android.view.ViewGroup.drawChild(ViewGroup.java:2892) at
  android.view.ViewGroup.dispatchDraw(ViewGroup.java:2494) at
  android.view.ViewGroup.drawChild(ViewGroup.java:2890) at
  android.view.ViewGroup.dispatchDraw(ViewGroup.java:2494) at
  android.view.ViewGroup.drawChild(ViewGroup.java:2890) at
  android.widget.ListView.drawChild(ListView.java:3231) at
  android.view.ViewGroup.dispatchDraw(ViewGroup.java:2494) at
  android.widget.AbsListView.dispatchDraw(AbsListView.java:2277) at
  android.widget.ListView.dispatchDraw(ListView.java:3226) at
  android.view.View.draw(View.java:11289) at
  android.widget.AbsListView.draw(AbsListView.java:3760) at
  android.view.ViewGroup.drawChild(ViewGroup.java:2892) at
  android.view.ViewGroup.dispatchDraw(ViewGroup.java:2494) at
  android.view.ViewGroup.drawChild(ViewGroup.java:2890) at
  android.view.ViewGroup.dispatchDraw(ViewGroup.java:2494) at
  android.view.ViewGroup.drawChild(ViewGroup.java:2890) at
  android.view.ViewGroup.dispatchDraw(ViewGroup.java:2494) at
  android.view.ViewGroup.drawChild(ViewGroup.java:2890) at
  android.view.ViewGroup.dispatchDraw(ViewGroup.java:2494) at
  android.view.ViewGroup.drawChild(ViewGroup.java:2890) at
  android.view.ViewGroup.dispatchDraw(ViewGroup.java:2494) at
  android.view.View.draw(View.java:11187) at
  android.widget.FrameLayout.draw(FrameLayout.java:450) at
  com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2291)
  at android.view.ViewRootImpl.draw(ViewRootImpl.java:2210) at
  android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1816) at
  android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2628) at
  android.os.Handler.dispatchMessage(Handler.java:99) at
  android.os.Looper.loop(Looper.java:137) at
  android.app.ActivityThread.main(ActivityThread.java:4511) at
  java.lang.reflect.Method.invokeNative(Native Method) at
  java.lang.reflect.Method.invoke(Method.java:511) at
  com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747) at
  dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>The frustrating part is that this originates from within android itself - and has no starting point at my code.
  After doing some research this happens only for Hebrew users and i found this link to Google bug -
  <a href="http://code.google.com/p/android/issues/detail?id=30889">http://code.google.com/p/android/issues/detail?id=30889</a></p>
  
  <p>I naturally tried to contact the writer and the Google employee assigned to this bug - none of them has the curtsey or replying.</p>
  
  <p>My related code which sets the span is:</p>
  
  <pre><code>if(searchTerm!=null){
      try{
          Spannable str = (Spannable) name.getText();
          int s_ind = fi.getSearchName().indexOf(searchTerm);
          str.setSpan(new ForegroundColorSpan(Color.BLACK),s_ind, (s_ind+searchTerm.length()), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
          str.setSpan(new BackgroundColorSpan(Color.YELLOW),s_ind, (s_ind+searchTerm.length()), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
          str.setSpan(new StyleSpan(android.graphics.Typeface.BOLD),s_ind, (s_ind+searchTerm.length()), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
      }catch(Exception ex){
          FLogger.logE(DW_CODES.PREDEFINED_ERROR, "Exception while searching for view in predefined "+ex.getMessage());
      }
  }
  </code></pre>
  
  <p>Search term is a part of the name.
  I want to mark the searchTerm part with different color so it will be more visible to the user.</p>
  
  <p>I invested truly many hours on this and since i didn't even managed to recreate it on my 4 test devices and 8 AVD's I am kind of lost.
  Any tips \ Suggestions to do the same without Spannables, will be greatly appreciated.</p>