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

java.io.PrintWriter.setError() method does not work starting from 1.6

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 6u29
    • Fix Version/s: None
    • Component/s: core-libs
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_29"
      Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
      Java HotSpot(TM) Server VM (build 20.4-b02, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux r70 2.6.37.6-0.9-desktop #1 SMP PREEMPT 2011-10-19 22:33:27 +0200 i686 i686 i386 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      According to the java.io.PrintWriter documentation after the setError() method is called the checkError() method should return "true". It does not work so starting with JRE 1.6.

      Here is a simple test (TestPrintWriter.java) that illustrates the problem.

      import java.io.PrintWriter;
      import java.io.OutputStream;

      public class TestPrintWriter {

        static class MyPrintWriter extends PrintWriter {
             public MyPrintWriter(OutputStream out) {
                 super(out);
             }

             public void myMethod() {
                 setError();
             }
        }

        public static void main(String[] args) {
             MyPrintWriter pw = new MyPrintWriter(System.out);
             pw.myMethod(); // myMethod sets an error
             if (pw.checkError())
                 System.out.println("Test passed");
             else
                 System.out.println("Test failed");
         }
      }

      Here are results of running the test with Java 1.5 and 1.6

      /u01/osv > /usr/lib/jvm/java-1.5.0-sun-1.5.0/bin/java -cp . TestPrintWriter
      Test passed
      /u01/osv > /usr/lib/jvm/java-1.6.0-sun-1.6.0/bin/java -cp . TestPrintWriter
      Test failed


      REGRESSION. Last worked in version 5.0


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.PrintWriter;
      import java.io.OutputStream;

      public class TestPrintWriter {

        static class MyPrintWriter extends PrintWriter {
             public MyPrintWriter(OutputStream out) {
                 super(out);
             }

             public void myMethod() {
                 setError();
             }
        }

        public static void main(String[] args) {
             MyPrintWriter pw = new MyPrintWriter(System.out);
             pw.myMethod(); // myMethod sets an error
             if (pw.checkError())
                 System.out.println("Test passed");
             else
                 System.out.println("Test failed");
         }
      }

      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            Assignee:
            sherman Xueming Shen
            Reporter:
            mbankal Mala Bankal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Imported: