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

Console.readLine() throws misleading IOError after InputStreamReader(System.in).close()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Won't Fix
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      The Exception is misleading and closing InputStreamReader(System.in) does not allow Console.readLine() to read a line and Console.readPassword() to read password.
      For Console.readPassword(), exception message is: IOError :java.io.IOException: The handle is invalid. See Result2:
      Closing InputStreamReader(System.in) should not affect Console readLine(),readPassword() methods.
      Please see the following code,Result1.
      <code>
      import java.io.*;
      class TestClose4 {
        public static void main(String... s){
         Console con =System.console();
         try{
            InputStreamReader reader = new InputStreamReader(System.in);
            reader.close();
            String st=con.readLine("%s","Enter a line");
            System.out.println(st);
         }catch(IOException e){
            e.printStackTrace();
         }catch(IOError error){
            error.printStackTrace();
         }
       }
      }
      </code>
      <Result1>
      C:\work>java TestClose4
      Enter a linejava.io.IOError: java.io.IOException: No such file or directory
              at java.io.Console.readLine(Console.java:236)
              at TestClose4.main(TestClose4.java:9)
      Caused by: java.io.IOException: No such file or directory
              at java.io.FileInputStream.readBytes(Native Method)
              at java.io.FileInputStream.read(FileInputStream.java:199)
              at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)
              at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)
              at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)
              at java.io.Console$LineReader.read(Console.java:409)
              at java.io.Console.readline(Console.java:348)
              at java.io.Console.readLine(Console.java:232)
              ... 1 more
      </Result1>

      <Result2>
      C:\work>java TestClose4
      Enter a Passwordjava.io.IOError: java.io.IOException: The handle is invalid
              at java.io.Console.readPassword(Console.java:302)
              at TestClose4.main(TestClose4.java:10)
      Caused by: java.io.IOException: The handle is invalid
              at java.io.Console.echo(Native Method)
              at java.io.Console.readPassword(Console.java:299)
              ... 1 more
      </Result2>

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: