JDK-4471563 : jdk regression: FileWriter.write() incorrectly writes the characters
  • 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-06-19
  • Updated: 2001-06-19
  • Resolved: 2001-06-19
Related Reports
Duplicate :  
Description

Name: auR10023			Date: 06/19/2001



Method FileWriter.write(char[], int, int) incorrectly writes the characters.
Following example shows that only 5064 characters can be read from file which
was filled by 1000 characters. It concerns only jdk1.4. In jdk1.3 everything is
ok.


Here is the example:

------ t.java -----

import java.io.*;

class t {
    public static void main(String[] args) {
        int numOfCharsToRead = 10000;
        char[] loadingChars = new char[numOfCharsToRead];
        char[] inChars = new char[numOfCharsToRead];
        for(int i=0;i<loadingChars.length; ++i) {
            loadingChars[i] = (char) i;
        }
        File tempFile = new File("tmp");
        try {
            FileWriter fw = new FileWriter(tempFile);
            fw.write(loadingChars, 0, loadingChars.length);
            fw.close();

            FileReader fr = new FileReader(tempFile);

            int  returnValue = fr.read(inChars, 0, numOfCharsToRead);
            System.out.println("read:" + returnValue);
        } catch (Exception e) {
            System.out.println( e);
        }

    }
}

#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 t                                                                         

read:10000


#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 t                                                                         

read:5064

This example creates tmp file in the current directory. This file has 
length 10000 when the example runs under jdk1.3 and it has length 5064 when 
the example runs under jdk1.4. 

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