S
Spencer Rugaber
I ran across an interesting bug, which I have isolated to the
following:
/* 1*/ import java.io.*;
/* 2*/ public class WordCount {
/* 3*/ public static void main (String[] args) {
/* 4*/ InputStreamReader tr = new InputStreamReader(System.in);
/* 5*/ try {
/* 6*/ tr.read(); /* Input intentionally ignored */
/* 7*/ } catch (Exception e) {
/* 8*/ System.exit(-1);
/* 9*/ }
/*10*/ System.out.println(0);
/*11*/ System.exit(0);
/*12*/ }
/*13*/ }
When run with input consisting of an empty file from standard in,
the output is a line consisting only of "0D".
If input is from a file, rather than the command line, the program
works, printing only "0". If lines 4-9 are removed, the program
works.
The problems, occurs in Java 1.3, 1.4, 1.5. It occurs on Linux,
Solaris and Windows systems.
The only thoughts I have are 1) that somehow stdin and stdout both
being the terminal confuses things, or 2) somehow, conversion between
bytes and ints is a problem.
I can't be the first person to notice this problem. All suggestions
appreciated.
Thanks.
Spencer
--
Spencer
-------
Spencer Rugaber
2406 Klaus Advanced Computing Building
College of Computing, Georgia Tech, Atlanta GA 30332-0280
Internet: (e-mail address removed)
Phone: (404) 894-8450 Fax: (404) 894-9442
WWW: http://www.cc.gatech.edu/fac/Spencer.Rugaber
following:
/* 1*/ import java.io.*;
/* 2*/ public class WordCount {
/* 3*/ public static void main (String[] args) {
/* 4*/ InputStreamReader tr = new InputStreamReader(System.in);
/* 5*/ try {
/* 6*/ tr.read(); /* Input intentionally ignored */
/* 7*/ } catch (Exception e) {
/* 8*/ System.exit(-1);
/* 9*/ }
/*10*/ System.out.println(0);
/*11*/ System.exit(0);
/*12*/ }
/*13*/ }
When run with input consisting of an empty file from standard in,
the output is a line consisting only of "0D".
If input is from a file, rather than the command line, the program
works, printing only "0". If lines 4-9 are removed, the program
works.
The problems, occurs in Java 1.3, 1.4, 1.5. It occurs on Linux,
Solaris and Windows systems.
The only thoughts I have are 1) that somehow stdin and stdout both
being the terminal confuses things, or 2) somehow, conversion between
bytes and ints is a problem.
I can't be the first person to notice this problem. All suggestions
appreciated.
Thanks.
Spencer
--
Spencer
-------
Spencer Rugaber
2406 Klaus Advanced Computing Building
College of Computing, Georgia Tech, Atlanta GA 30332-0280
Internet: (e-mail address removed)
Phone: (404) 894-8450 Fax: (404) 894-9442
WWW: http://www.cc.gatech.edu/fac/Spencer.Rugaber