Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6248507
Votes 0
Synopsis AbstractStringBuilder.replace does not handle count < start < end
Category java:classes_lang
Reported Against
Release Fixed mustang(b47), 5.0u6(b03) (Bug ID:2128139)
State 10-Fix Delivered, bug
Priority: 3-Medium
Related Bugs
Submit Date 31-MAR-2005
Description
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 ----------
  xxxxx@xxxxx   2005-03-31 05:48:12 GMT
Work Around
N/A
Evaluation
Oops.  Trivial modification to provide correct exception detail message.
  xxxxx@xxxxx   2005-06-15 22:06:10 GMT
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang