The following program
---------------------------------------------------
import java.util.*;
import java.nio.*;
import java.nio.charset.*;
public class DecoderOverflow {
static int failures = 0;
public static void main(String[] args) throws Exception {
for (String csn : Charset.availableCharsets().keySet()) {
// The following 3 charsets are broken as of 2004-09-17
// if (csn.equals("JIS_X0212-1990")) continue;
// if (csn.equals("x-JIS0208")) continue;
// if (csn.equals("x-ISCII91")) continue;
try {
test(csn);
} catch (Throwable t) {
System.out.println(csn);
t.printStackTrace();
failures++;
}
}
if (failures > 0)
throw new Exception(failures + " charsets failed");
}
static void test(String encoding) throws Exception {
String text = "Vote for Duke!";
Charset cs = Charset.forName(encoding);
if (! cs.canEncode() || ! cs.newEncoder().canEncode('.')) return;
ByteBuffer in = ByteBuffer.wrap(text.getBytes(encoding));
CharBuffer out = CharBuffer.allocate(text.length()/2);
CoderResult result = cs.newDecoder().decode(in, out, true);
if (out.hasRemaining() || ! result.isOverflow())
throw new Exception
("out.hasRemaining()=" + out.hasRemaining() +
" result.isOverflow()=" + result.isOverflow() +
" in.capacity()=" + in.capacity() +
" encoding=" + encoding);
}
}
-----------------------------------------------------
fails as follows:
----------System.out:(3/35)----------
JIS_X0212-1990
x-ISCII91
x-JIS0208
----------System.err:(43/2680)----------
java.lang.Exception: out.hasRemaining()=true result.isOverflow()=false in.capacity()=14 encoding=JIS_X0212-1990
at DecoderOverflow.test(DecoderOverflow.java:40)
at DecoderOverflow.main(DecoderOverflow.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:83)
at java.lang.Thread.run(Thread.java:595)
java.lang.ArrayIndexOutOfBoundsException: 7
at sun.nio.cs.ext.ISCII91$Decoder.decodeArrayLoop(ISCII91.java:635)
at sun.nio.cs.ext.ISCII91$Decoder.decodeLoop(ISCII91.java:782)
at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:542)
at DecoderOverflow.test(DecoderOverflow.java:38)
at DecoderOverflow.main(DecoderOverflow.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:83)
at java.lang.Thread.run(Thread.java:595)
java.lang.Exception: out.hasRemaining()=true result.isOverflow()=false in.capacity()=14 encoding=x-JIS0208
at DecoderOverflow.test(DecoderOverflow.java:40)
at DecoderOverflow.main(DecoderOverflow.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:83)
at java.lang.Thread.run(Thread.java:595)