JDK-4092733 : java.io.BufferedReader.readLine blocks when reading from keyboard (win95)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.1.3,1.1.5
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-11-13
  • Updated: 1998-04-28
  • Resolved: 1998-04-28
Related Reports
Duplicate :  
Description
Name: bk70084			Date: 11/13/97


To reproduce this bug, enter a character and hit <Enter> as quickly as you
can afterwards. 

If a bufferedReader class is created from System.in, 

getLine() will occasionally block after <Enter> is
pressed, and a 2nd <Enter> has to be pressed, before the thread can continue.
Then 2 <Enters> will be seen to have been pressed.


//---------------Test.java------------------
import java.io.*;

public class Test
{
    public static void main(String[] args)
    {
        InWindow i = new InWindow();
        String s = i.cmdEnter();
        System.out.println("Entered \"" + s + "\"");
    }
}

class InWindow {
BufferedReader kbdstream;


    InWindow()
    {

    kbdstream=new BufferedReader(new InputStreamReader(System.in));
    }


    String readLine()
    {
    try {
        return kbdstream.readLine();
        }
    catch(IOException e)
        {
        return null;
        }
    }


    String cmdEnter()
    {
    System.out.print("Enter Command, ? for help : ");
    return readLine();
    }

}

(Review ID: 19916)
======================================================================

Comments
WORK AROUND Name: bk70084 Date: 11/13/97 ======================================================================
11-06-2004