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

Console.writer/readLine/rePassword does not work after closing the System.out/in

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      The PrintWriter Stream associated with Console.writer() closes/doesn't work whenever we close stream OutputStreamWriter(System.out).The follwing program displays nothing on the console.After flushing the stream con.flush(), "Hi Duke" is not displaying on the console.
      It has not been mentioned in the spec that, closing the other output streams will affect the Console methods Console.format(String fmt,Object... object),printf(),readLine(String fmt,Object... object).
      Please see the following version,code and Result.
      <version>
      C:\work>java -version
      java version "1.6.0-auto"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0-auto-309)
      Java HotSpot(TM) Client VM (build 1.6.0-beta-b60, mixed mode)
      </version>

      <code>
      import java.io.*;
      class TestClose3{
        public static void main(String ... s1) {
         Console con = System.console();
         try{
           OutputStreamWriter writer = new OutputStreamWriter(System.out);
           writer.close();
           con.printf("hello Java");
           String ln=con.readLine("%s","Enter Line");
           con.printf("line Entered %s",ln);
           char ch[] = new char[20];
           ch=con.readPassword("%s","Enter password");
           con.format("Password Entered %s",new String(ch));
           Writer riter = con.writer();
           riter.write("Hi Duke",0,6);
           con.flush();
           
          }catch(Exception e){
            e.printStackTrace();
          }

        }
      }
      </code>
      <Result>
      (Nothing displayed on the console except those characters typed.)
      </Result>
      Console's input/output methods no longer work after closing the System.in/out.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              sherman Xueming Shen
              Reporter:
              rgutupalsunw Rajendra Gutupalli (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: