JDK-4066847 : java.io.OutputStreamWriter incorrectly throw CharConversionException
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.1.3
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 1997-07-23
  • Updated: 1998-06-19
  • Resolved: 1998-06-19
Related Reports
Duplicate :  
Description

Name: el35337			Date: 07/23/97


/*
C:>java BugChecker4
java.vendor: Sun Microsystems Inc.
java.version: 1.1.3
os.name: Solaris
os.arch: sparc

OutputStreamWriter bug: CharConversionException should not occur.
OutputStreamWriter bug: number of KSC5601 bytes written should be 20001, not be 19999

<<< Solution >>>
% diff jdk1.1.3/src/java/io/OutputStreamWriter.java bugpatch113/java/io/OutputStreamWriter.java
164c164
<                   if (nci == ci) {
---
>                   if (nci == ci && nextByte == 0) {

*/

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." );
        }
    }
}


company - KAIST , email - ###@###.###
======================================================================

Comments
WORK AROUND Name: el35337 Date: 07/23/97 ======================================================================
11-06-2004