Name: auR10023 Date: 03/19/2002
Method java.nio.channels.Channels.newReader(ReadableByteChannel ch,
CharsetDecoder dec, int minBufferCap) called with minBufferCap = 0, 1
and CharsetDecoder of the UTF-16 charset returns Reader with following
incorrect behavior:
if minBufferCap=1, obtained Reader hangs when Reader.read() operation is
performed. if minBufferCap=0, obtained Reader throws java.lang.Error
exception.
Here is the example:
-------------test.java--------------
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.nio.charset.*;
public class test {
public static void main(String[] args) {
try {
Charset cs = Charset.forName("UTF-16");
ByteArrayInputStream bis = new ByteArrayInputStream(new byte[100]);
ReadableByteChannel ch = Channels.newChannel(bis);
Reader r = Channels.newReader(ch, cs.newDecoder(),
Integer.parseInt(args[0]));
char [] arr = new char[10];
r.read(arr, 0, arr.length);
} catch (Exception e) {
System.out.println("Exception: ");
e.printStackTrace(System.out);
return;
}
}
}
#java -version
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
#java test 0
Exception in thread "main" java.lang.Error
at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:417)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:442)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:179)
at test.main(test.java:15)
#java test 1
-- hangs
======================================================================