Name: mf23781 Date: 06/10/98
(KO)OutputStreamWriter incorrectly throw CharConversionException.
java.io.OutputStreamWriter incorrectly throws CharConversionException.
We've tested it on three platforms, Merlin-K, Warp Server 4 and Warp Server SMP.
There should be no CharConversionException but it occured.
Here's a Test program.
-------------------Begin of Source----------------------------------------------import java.util.*;
import java.io.*;
class BugChecker4
{
public static void main(String[] args)
throws IOException
{
System.out.println( "java.vendor: " +
System.getProperty("java.vendor") );
System.out.println( "java.version: " +
System.getProperty("java.version") );
System.out.println( "os.name: " + System.getProperty("os.name"));
System.out.println( "os.arch: " + System.getProperty("os.arch"));
System.out.println();
ByteArrayOutputStream bos;
OutputStreamWriter osw;
byte[] array;
bos = new ByteArrayOutputStream();
osw = new OutputStreamWriter(bos, "EUCJIS");
osw.write('a');
try{
for(int count = 0; count < 10000; ++count)
osw.write('\u3042'); // Hiragana
osw.close();
array = bos.toByteArray();
if ( array.length != 20001 )
System.out.println( "OutputStreamWriter bug: number of EUCJIS bytes written should be 20001, " + "not be " + array.length );
}
catch( CharConversionException ex){
System.out.println( "OutputStreamWriter bug: CharConversionException should not occur." );
}
bos = new ByteArrayOutputStream();
osw = new OutputStreamWriter(bos, "KSC5601");
osw.write('a');
try{
for(int count = 0; count < 10000; ++count)
osw.write('\uac00'); // Hangul syllable
osw.close();
array = bos.toByteArray();
if ( array.length != 20001 )
System.out.println( "OutputStreamWriter bug: number of KSC5601 bytes written should be 20001, " + "not be " + array.length );
}
catch( CharConversionException ex ){
System.out.println( "OutputStreamWriter bug: CharConversionException should not occur." );
}
}
}
---------------------End of Source--------------------------------------------
The problem also fails on AIX ( a116-19980516 ) and Win95.
There is a related Sun defect reported against 1.1.3 for the same
testcase, but with a different failure and actually occuring later.
( Bug ID 4066847 ).
The problem seems to be with the method "writer" in OutputStreamWriter.
The writer converts characters to bytes using the chartobyte converter.
This uses a buffer of fixed length 8192. When the buffer becomes full
it should automatically be flushed.
The problem occurs when we have written out 8191 bytes and then
attempt to write out a multi-byte character. The buffer has not
yet been flushed, but the buffer thinks it cannot even hold one
character. At this point we throw:
> java.io.CharConversionException: Output buffer too small
As this is a cross-platform problem in the shared code I suggest
not to fix it for GA but to raise it as a Sun defect.
This problem can also be re-created on Solaris (duke).
======================================================================