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: 6546113
Votes 0
Synopsis (bf) CharSequence.slice() on wrapped CharSequence doesn't start at buffer position
Category java:classes_nio
Reported Against
Release Fixed 7(b25), 6u10(b31) (Bug ID:2164054)
State 10-Fix Delivered, bug
Priority: 2-High
Related Bugs 6795561 , 4997655
Submit Date 13-APR-2007
Description
FULL PRODUCT VERSION :
java version "1.6.0"
Java(TM) SE Runtime Environment (build 1.6.0-b105)
Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)


ADDITIONAL OS VERSION INFORMATION :
Linux moonlight 2.6.20-14-generic #2 SMP Mon Apr 2 20:37:49 UTC 2007 i686 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
When slicing a CharSequence wrapping CharBuffer, the resulting CharBuffer appears to be incorrect. According to the specs, the resulting sliced buffer should start at the original buffer's position. So, slicing 'Hello World' at position 4 and limit 7 should create a buffer that has 'o W' in it. But instead it has 'Hel'. This is demonstrated by the following testcase. Wrapping a char array instead shows the expected result.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try attached test program.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Wrapping the char sequence should yield 'o W'
ACTUAL -
Wrapping the char sequence yields 'Hel'

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.nio.CharBuffer;

public class TestCharSequenceBuffer {

  public static void main(String[] args) {
    CharBuffer cb = CharBuffer.wrap("Hello World");
    cb.position(4);
    cb.limit(7);
    CharBuffer sl = cb.slice();
    System.out.println("wrapping a CharSequence");
    System.out.println("expected: 'o', result: '" + sl.get() + "'");
    System.out.println("expected: ' ', result: '" + sl.get() + "'");
    System.out.println("expected: 'W', result: '" + sl.get() + "'");


    cb = CharBuffer.wrap("Hello World".toCharArray());
    cb.position(4);
    cb.limit(7);
    sl = cb.slice();
    System.out.println("wrapping a char[]");
    System.out.println("expected: 'o', result: '" + sl.get() + "'");
    System.out.println("expected: ' ', result: '" + sl.get() + "'");
    System.out.println("expected: 'W', result: '" + sl.get() + "'");
  }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Convert the char sequence to a char[] and wrap this.

Release Regression From : 5.0u10
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.
Posted Date : 2007-04-13 22:28:38.0
Work Around
N/A
Evaluation
See 4997655.
Posted Date : 2007-04-15 20:38:23.0
Comments
  
  Include a link with my name & email   

Submitted On 27-SEP-2007
Posted possible fix in:
http://mail.openjdk.java.net/pipermail/core-libs-dev/2007-September/000075.html



PLEASE NOTE: JDK6 is formerly known as Project Mustang