Patch Set 3: I would prefer that you didn't submit this

In this case you don't need to catch the IAE: 'o' is an offset and hence you can simply check that it's not exceeding the text:

StyleRange r= null;
if (o < t.getCharCount())
	r= t.getStyleRangeAtOffset(o);