JDK-4080163 : java.io.BufferedReader.readLine() intermittently fails to see EOL
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.1.3,1.1.4
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_95
  • CPU: x86
  • Submitted: 1997-09-18
  • Updated: 1998-04-28
  • Resolved: 1998-04-28
Related Reports
Duplicate :  
Description

Name: rm29839			Date: 09/18/97


import java.io.*;
  // Program to demo BufferedReader problem
  // Eventually readLine() fails to recognize the Enter key being pressed
  // It can take some time although it can be quite quick.
  // It seems to be randome but maybe it depends on whats in the buffer
  // It is not repeatable - the same input does not necessarily fail.

  public class TestBufferedReader
  {

    //***************************************************************************
    //  main()
    //***************************************************************************
    public static void main(String[] args)
    {
       BufferedReader  kb = new BufferedReader(
                                 new InputStreamReader(System.in));
        String text = " ";
      try
      {
        while (text.length() != 0)
        {
          System.out.print("Enter some text - empty line to end: ");
          text = kb.readLine().trim();
          System.out.println("\n Text length = "+text.length());
        }
      } // end try
      catch (Exception e)
      {
        System.out.println(e);
      } // end catch Exception
    } // end main()

  }

Sample output - you can see where the end of input was not recognized:

Enter some text - empty line to end: eeeeeeeee

 Text length = 9
Enter some text - empty line to end: fffffff

 Text length = 7
Enter some text - empty line to end: fffffffff

 Text length = 9
Enter some text - empty line to end: bbbbbbbbb

 Text length = 9
Enter some text - empty line to end: vvvvvvvv

 Text length = 8
Enter some text - empty line to end: cccccc
yyyyyyyyyy
yyyyyy
yyy
yyyyyyyyy
yyyyy
yyyyyy
yyyyyyyy
yyyyyy
yyyyyyyyy

 Text length = 6
Enter some text - empty line to end:
 Text length = 10
Enter some text - empty line to end:
 Text length = 6
Enter some text - empty line to end:
 Text length = 3
Enter some text - empty line to end:
 Text length = 9
Enter some text - empty line to end:
 Text length = 5
Enter some text - empty line to end:
 Text length = 6
Enter some text - empty line to end:
 Text length = 8
Enter some text - empty line to end:
 Text length = 6
Enter some text - empty line to end:
 Text length = 9
Enter some text - empty line to end:

 Text length = 0

company - n/a , email - ###@###.###
======================================================================

Comments
WORK AROUND Name: rm29839 Date: 09/18/97 ======================================================================
11-06-2004