Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4471563

jdk regression: FileWriter.write() incorrectly writes the characters

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Duplicate
    • Affects Version/s: 1.4.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.6

      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.

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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              avusunw Avu Avu (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: