-
Bug
-
Resolution: Fixed
-
P2
-
1.4.0, 6u10, 6u14
-
b57
-
generic, x86, sparc
-
linux, solaris, solaris_8
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2183343 | 6u18 | Abhijit Saha | P4 | Resolved | Fixed | b03 |
JDK-2183413 | 6u17-rev | Abhijit Saha | P4 | Resolved | Fixed | b05 |
JDK-2178801 | 6u16-rev | Abhijit Saha | P4 | Closed | Fixed | b03 |
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Linux tank 2.6.24-23-generic #1 SMP Thu Nov 27 18:13:46 UTC 2008 x86_64 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
StringCharBuffer.subSequence(start,end) creates a new StringCharBuffer with the wrong capacity value. The current buffer's remaining() value is used as the new buffer's capacity. This causes an IndexOutOfBoundsException when the absolute value of the end index (the new buffer's limit) is greater than remaining().
Previously (before jdk6u10) the new buffer's capacity was the same as the wrapped string's length. This problem is also present in 6u11.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. javac CharBufTest.java
2. java CharBufTest
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Result: test
ACTUAL -
Exception in thread "main" java.lang.IndexOutOfBoundsException
at java.nio.StringCharBuffer.subSequence(StringCharBuffer.java:92)
at CharBufTest.main(CharBufTest.java:9)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.nio.CharBuffer;
public class CharBufTest {
public static void main(String[] args) {
// Create a 15-char StringCharBuffer via CharBuffer.wrap()
CharBuffer cb = CharBuffer.wrap("This is a test.");
// Attempt to select the subsequence "test", starting at position=10
cb.position(10);
// Absolute value of end index below (10+4) is greater than remaining (5)
CharSequence s = cb.subSequence(0, 4); // Fails on jdk6u10 and newer
System.out.println("Result: " + s);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Works OK as long as absolute end index is <= remaining(). Could use slice() first to enforce this.
Release Regression From : 6u6
The above release value was the last known release where this
bug was not reproducible. Since then there has been a regression.
- backported by
-
JDK-2183343 (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
- Resolved
-
JDK-2183413 (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
- Resolved
-
JDK-2178801 (bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
- Closed
- duplicates
-
JDK-4511104 (bf spec) CharBuffer.subSequence() specification incorrect
- Closed
- relates to
-
JDK-6546113 (bf) CharSequence.slice() on wrapped CharSequence doesn't start at buffer position
- Closed
-
JDK-4997655 (bf) CharBuffer.slice() on wrapped CharSequence results in wrong position()
- Resolved