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

PrintStream.print(char) flushes more than write(char) contrary to spec

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs
    • Fix Understood
    • generic
    • solaris_8

      According to the specification for PrintStream.print(char), the following two
      programs are required to have identical behavior when the default output
      encoding is ASCII, UTF8, ISO8859-1, or any other encoding that translates an
      ASCII character to its corresponding byte. However, these two programs have
      different output. PrintStream.print(char) is improperly flushing the output,
      in violation of its specification.

      There are many other methods in PrintStream that violate their spec in exactly
      this manner. See, for example, print(boolean) and print(int).

      ==========$ cat -n T.java
           1 class T {
           2 public static void main(String[] args) {
           3 System.out.print('h');
           4 System.err.println("done");
           5 }
           6 }
           7 class U {
           8 public static void main(String[] args) {
           9 System.out.write((int)'h');
          10 System.err.println("done");
          11 }
          12 }
      ==========$ /java/re/j2se/1.5.0/nightly/binaries/`platform`/latest/bin/javac T.java
      ==========$ /java/re/j2se/1.5.0/nightly/binaries/`platform`/latest/bin/java T
      hdone
      ==========$ /java/re/j2se/1.5.0/nightly/binaries/`platform`/latest/bin/java U
      done
      ==========$ /java/re/j2se/1.5.0/nightly/binaries/`platform`/latest/bin/java -version
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b49)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b49, mixed mode)
      ==========$

            Unassigned Unassigned
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: