-
Bug
-
Resolution: Fixed
-
P4
-
1.1.5, 1.1.8, 1.2.0
-
kestrel
-
generic, x86
-
generic, windows_nt
Name: paC48320 Date: 06/22/98
In any system where \r alone is used for marking the EOL,
both of these classes will block until another character
is available after the \r to determine if it is a \n, even
though either alone are considered to be enough for an EOL.
This causes extreme problems in streaming data situations
(especially where the data rate is low) since the previous
line is not returned until the next is available.
In our situation, we are looking for an end of message
identifier (which is \r terminated, as are other lines)
to indicate to the consumer that it has received an entire
packet of data. In some cases, this delays the EOM detection
until the consumer is no longer interested in the data.
It is further aggravating in a system where you want to
support multiple VM versions (but then I am sure you already
know that) since we can't guarantee it's been fixed in this
version, programatically.
(Review ID: 28708)
======================================================================
Name: krT82822 Date: 05/07/99
I just reported this problem and was assigned bug number 4236469
but the person who review the bug did not completely understand
the nature of the bug. The issue is that the BufferedReader
readLine() method requires an extra byte to show up at the end
of a line that has a <CR> line ending before it will return
the line. This has caused many hours of frustration trying to
get some applets to work with the Mac platform.
The following are two simple example classes that show the
problem:
import java.io.PrintWriter;
import java.io.PipedWriter;
import java.io.PipedReader;
import java.io.BufferedReader;
/**
* This shows the bug with the buffered reader...
*/
public class ShowBug10
{
public static void main(String[] args) throws java.io.IOException
{
PipedReader pipe = new PipedReader();
PrintWriter writePipe=new PrintWriter(new PipedWriter(pipe));
BufferedReader readPipe=new BufferedReader(pipe);
System.out.println("This fails to run on a Mac platform!!!");
// This will fail to run if the println() method uses
// the platform line endings and that line ending is CR-only
// AKA - a Mac platform system...
writePipe.println("Hello!");
System.out.println("> " + readPipe.readLine());
}
}
and
import java.io.PrintWriter;
import java.io.PipedWriter;
import java.io.PipedReader;
import java.io.BufferedReader;
/**
* This shows the bug with the buffered reader...
* <P>
* Note that I hard-code the line endings here to
* make sure all three types are tried...
*/
public class ShowBug9
{
public static void main(String[] args) throws java.io.IOException
{
PipedReader pipe = new PipedReader();
PrintWriter writePipe=new PrintWriter(new PipedWriter(pipe));
BufferedReader readPipe=new BufferedReader(pipe);
System.out.println("First, we will render all three types at once:");
// NOTE!!! Order matters!!! If no data after the last CR the output will stop
// So, if you output CR-Only *last* it will fail to run.
writePipe.print("CR-Only\r");
writePipe.print("LF-Only\n");
writePipe.print("CR/LF\r\n");
// Now print the three lines:
System.out.println("> " + readPipe.readLine());
System.out.println("> " + readPipe.readLine());
System.out.println("> " + readPipe.readLine());
// Now, do them one at a time
System.out.println("");
System.out.println("Now, one at a time (CR-Only is last because it fails this way:");
// Now, this program should exit but does not because of the last line...
writePipe.print("CR/LF\r\n");
System.out.println("> " + readPipe.readLine());
writePipe.print("LF-Only\n");
System.out.println("> " + readPipe.readLine());
writePipe.print("CR-Only\r");
System.out.println("> " + readPipe.readLine());
}
}
NOTE! This happens in JDK 1.1.x (all versions) and JDK 1.2.
Also note that I am a JDK licensee (and porter for the Linux
platform) and have checked this on Linux, Windows, Solaris,
FreeBSD, and Mac platforms (so far).
(Review ID: 57978)
======================================================================
- duplicates
-
JDK-4262765 readLine() of BufferedReader & DataInputStream hangs on CR-only input
-
- Closed
-