|
Quick Lists
|
|
Bug ID:
|
6795561
|
|
Votes
|
2
|
|
Synopsis
|
(bf) CharBuffer.subSequence() uses wrong capacity value for new buffer
|
|
Category
|
java:classes_nio
|
|
Reported Against
|
merlin-beta3
|
|
Release Fixed
|
7(b57)
|
|
State
|
10-Fix Delivered,
bug
|
|
Priority:
|
2-High
|
|
Related Bugs
|
4511104
,
6546113
,
4997655
|
|
Submit Date
|
20-JAN-2009
|
|
Description
|
FULL PRODUCT VERSION :
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.
Posted Date : 2009-01-20 10:00:03.0
|
|
Work Around
|
N/A
|
|
Evaluation
|
The submitter is correct and there is a regression since 6u10. The regression is caused by the changes for 6546113 that went into 6u10 to address problems caused by 4997655. Yes, we goofed big time here. These issues should have been caught during code review or by tests. Our plan for this issue is to fix it in jdk7 first and let it bake before doing into a jdk6 update.
Posted Date : 2009-03-09 13:23:01.0
|
|
Comments
|
Submitted On 12-SEP-2009
Hi,
I'm using jdk1.6.0_16 and the is still there. Any idea when is it going to be fixed in jdk 1.6?
Thank you.
Submitted On 22-SEP-2009
elving
I don't understand why Sun is sitting on a serious regression that was introduced in a maintenance release. Given that StringCharBuffer.subSequence is now totally broken in mustang, I don't understand why you're waiting for the fix to bake in dolphin.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |