JDK-4219653 : BufferedReader.readLine() fails reading EOF from Socket
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 1.1.7
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_nt
  • CPU: x86
  • Submitted: 1999-03-12
  • Updated: 1999-03-12
  • Resolved: 1999-03-12
Description

Name: dbT83986			Date: 03/11/99


When making a socket connection to *certain* servers, BufferedReader.readLine() (or read() and read(char[], int, int] for that matter)
fails to recognize EOF.

One such server is Sun's FTP server (ftp.sun.com).  Observe the following code.

package MyUtils;

import java.io.*;
import java.net.*;

public class FTPTest
{
  public static void main(String[] args)
  {
    try {
      Socket sock = new Socket("ftp.sun.com", 21);
      sock.setSoTimeout(10000);
      BufferedReader reader = new BufferedReader(new
        InputStreamReader(sock.getInputStream()));

      String line = reader.readLine();
      System.out.println("line: [" + line + "]");
      while (line != null) {
        line = reader.readLine();
        System.out.println("line: [" + line + "]");
      }
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    finally {
    }
  }
}

---

This code generates this output:

line: [220-Welcome to Sun Microsystems Corporate FTP Server.]
line: [220-]
line: [220 ftp FTP server (ftpd Wed Oct 30 23:31:06 PST 1996) ready.]
java.io.InterruptedIOException: Read timed out
        at java.net.SocketInputStream.read(SocketInputStream.java:84)
        at java.net.SocketInputStream.read(SocketInputStream.java:67)
        at java.io.InputStreamReader.fill(Compiled Code)
        at java.io.InputStreamReader.read(InputStreamReader.java:227)
        at java.io.BufferedReader.fill(Compiled Code)
        at java.io.BufferedReader.readLine(Compiled Code)
        at PDUtils.FTPTest.main(Compiled Code)
(Review ID: 55258)
======================================================================

Comments
EVALUATION I'm not an expert on FTP protocol, but... EOF is only reported on an InputStream from a Socket when the peer shuts down or closes the socket such that nothing more will ever be written to the socket by the remote process and nothing more will ever be received and made readable on the Socket instance via the InputStream. That doesn't seem to be case with this sample program. I don't see any bugs here. The sample client connects to the FTP server and gets a 220 "Service ready for new user" hello message from the server. This is normal. The client is then expected to send an FTP command to the server which will then result in a reply etc. etc. The sample program never sends any FTP commands after connecting. It just sits there waiting for the FTP server to spontaneously send more data (shouldn't happen) or spontaneously close the socket from it's end (shouldn't happen). When 10000 milliseconds pass without anything happening, the Socket's input stream throws an InterruptedIOException as requested via setSoTimeout(), prints the exception trace an exists. This is exactly what is supposed to happen. jeff.nisewanger@Eng 1999-03-11
11-03-1999