Backports
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8034668 | 7u65 | Ivan Gerasimov | P3 | Resolved | Fixed | b01 |
JDK-8023190 | 7u60 | Ivan Gerasimov | P3 | Closed | Fixed | b01 |
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
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
Attachments
Issue Links
- backported by
-
JDK-8034668 (str) Error in description of the method indexOf in the class StringBuffer
- Resolved
-
JDK-8023190 (str) Error in description of the method indexOf in the class StringBuffer
- Closed