JDK-4463205 : (cs) jdk regression:OutputStreamWriter.write incorrectly writes valid chars
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.4.0
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 2001-05-25
  • Updated: 2001-08-22
  • Resolved: 2001-07-19
Related Reports
Duplicate :  
Description

Name: auR10023			Date: 05/25/2001



OutputStreamWriter.write(char[]) incorrectly writes valid chars in  8859_1 
encoding.

Here is the test demonstrating the bug:

import java.io.*;

-----------CharacterEncodingTest01.java----------

public class CharacterEncodingTest01 {

    public static void main(String[] args) {
        String encoding = args[0];
        try {
            char chars[] = {
                'A', 'B',
                '\uFFF0',
                'a', 'b'
            };
            ByteArrayOutputStream baos = new ByteArrayOutputStream( );
            OutputStreamWriter writer = new OutputStreamWriter( baos, encoding );
            writer.write( chars );
            writer.flush();
            byte[] bytes = baos.toByteArray();
            System.out.println("TO STRING: " + baos.toString());

            if( bytes.length < chars.length ) {
                 System.out.println( "Incorrect number of bytes written: " +
                        bytes.length );
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

#> java -version
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)

#> java -cp . CharacterEncodingTest01 8859_1
TO STRING: AB?b
Incorrect number of bytes written: 4


#> java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, interpreted mode)

#> java -cp . CharacterEncodingTest01 8859_1
TO STRING: AB?ab

======================================================================

Comments
EVALUATION This is a duplicate of 4424392. java.nio.charset.CharsetEncoder always skips ahead by at least a single char when a non-mapped character is encountered on the input stream. The result is lost data. Ian.Little@Ireland 6/6/2001 There are actually several bugs that all report this same behaviour. I'm going to close this bug as duplicate fo 4457851 as it contains information about the relevant failing jck tests. iageng 2001-07-19
11-06-2004