FULL PRODUCT VERSION :
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
XP 5.1.2600
A DESCRIPTION OF THE PROBLEM :
If you call replace with start< end and both start and end indexes bigger than the size of the string, it throws a StringIndexOutOfBoundsException("start > end"). It should either
1) Not throw an exception. If end > count, it currently sets end = count, and just replaces to the end of the character sequence. It would be reasonable if it did the same thing for end > count and start > count - ie, append instead of replace.
2) Throw an exception with a better error message. Since start < end when the function is called, this error message is completely confusing, and would be utterly indecipherable to anyone who didn't have the source to look at. (On a related note, the actual "start > end" message could be improved to print out the start and end indexes as well).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
StringBuffer sb=new StringBuffer("string");
sb.replace(10,12,"buffer");
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Desired result: Either
1) sb becomes "stringbuffer" or
2) StringIndexOutOfBoundsException with message "start > number of characters (10 > 6)"
ACTUAL -
Result: StringIndexOutOfBoundsException with message start > end
(Even though start < end in the function call)
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: start > end
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
StringBuffer sb=new StringBuffer("string");
sb.replace(10,12,"buffer");
---------- END SOURCE ----------
###@###.### 2005-03-31 05:48:12 GMT