United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-8016018 : (str) Error in description of the method indexOf in the class StringBuffer

Details
Type:
Bug
Submit Date:
2013-04-04
Status:
Closed
Updated Date:
2014-02-12
Project Name:
JDK
Resolved Date:
2013-08-26
Component:
core-libs
OS:
Sub-Component:
java.lang
CPU:
Priority:
P3
Resolution:
Fixed
Affected Versions:
6,8
Fixed Versions:

Related Reports
Backport:
Backport:

Sub Tasks

Description
A DESCRIPTION OF THE PROBLEM :
The bug concerns the description of the method
public int indexOf(String str, int fromIndex) in the class StringBuffer.

In the documentaion we can see following misleading lines:
===
The integer returned is the smallest value k for which:
     k >= Math.min(fromIndex, str.length()) &&
                   this.toString().startsWith(str, k)
If no such value of k exists, then -1 is returned.
===
This statement is wrong. For example, consider this code:

                StringBuffer sb = new StringBuffer( " deabcabab " );
String str =  " ab " ;
int fromIndex = 6;
int k = 2;
System.out.println(k >= Math.min(fromIndex , str.length()));
System.out.println(sb.toString().startsWith(str,k));
System.out.println(k < sb.indexOf(str, fromIndex));
System.out.println(sb.indexOf(str, fromIndex));
output:
===
true
true
true
7
===




EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
===
The integer returned is the smallest value k for which:
     k >= Math.min(fromIndex, this.length()) &&
                   this.toString().startsWith(str, k)
===

cf. with the description of indexOf for String.

ACTUAL -
===
The integer returned is the smallest value k for which:
     k >= Math.min(fromIndex, str.length()) &&
                   this.toString().startsWith(str, k)
If no such value of k exists, then -1 is returned.
===

URL OF FAULTY DOCUMENTATION :
http://docs.oracle.com/javase/6/docs/api/java/lang/StringBuffer.html
                                    

Comments
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/92a66af7f834
User:  lana
Date:  2013-08-31 01:29:26 +0000

                                     
2013-08-31
URL:   http://hg.openjdk.java.net/jdk8/tl/jdk/rev/92a66af7f834
User:  coffeys
Date:  2013-08-26 17:34:47 +0000

                                     
2013-08-26



Hardware and Software, Engineered to Work Together