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

java.io.InputStreamReader assertion failure on single-character reads

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.4.0
    • core-libs
    • beta
    • sparc
    • solaris_2.6, solaris_8
    • Verified

      The following test case terminates with an assertion failure in Merlin build 46 (and it completes successfully in build 45):

      import java.io.*;

      public class TestStream {
          public static void main(String args[]) {
              try {
      InputStreamReader r = new InputStreamReader(
      new ByteArrayInputStream(new byte[] { 'X' }));
      char[] c = new char[1];
      r.read(c);
      System.out.println(c[0]);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }

      Here is the failure in build 46:

      Exception in thread "main" java.lang.Error
              at java.io.InputStreamReader$CharsetFiller.fill(InputStreamReader.java:353)
              at java.io.InputStreamReader.read(InputStreamReader.java:478)
              at java.io.Reader.read(Reader.java:103)
              at TestStream.main(TestStream.java:9)

      The problem seems to be this assertion in line 353 of InputStreamReader:

              int fill(char[] cbuf, int off, int end ) throws IOException {
                  if (!(end - off > 1)) throw new Error(); // ## assert

      which fails if (end - off) == 1, which seems to be a legitimate input as far as I can tell. Shouldn't the assertion be just

      if (!(end > off))

      ?

            mr Mark Reinhold
            peterjones Peter Jones (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: