This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

bug, possibly in InputStream class


greetings all...

i was using the attached program to play around with gcj, when all of a 
sudden...

i discovered a bug after compiling the attached program with gcj.  i do 
not have any idea if this bug has been reported before.

compiling the program with blackdown's compiler works fine, and the 
program runs without error(s).  it is only when it is compiled with gcj 
that the error occurs.

instead of exiting main at the end of the tail while loop, as it should 
(and does when run with blackdown's vm), the gcj-compiled version spits 
out a zero and sits patiently without exiting (waiting for the 
apocalypse, no doubt).

so i added some test code, and discovered that not only was the read 
method of InputStream not returning -1 when it had read all the input, 
it wasn't reading the full size of the buffer either, but rather 1460 
bytes; setting the buffer to smaller than 1460 is interesting, as with a 
buffer of 1024 bytes, the program reads in 1024 bytes, and then 436 
bytes, followed by 1024 and then 436 bytes, and so on.

anyway that is my amateur analysis of where the bug probably is.

regards.

/ben


-- 
|_     |_ | _  _ |_  	              "Never rub another man's rhubarb."
|_) .  |_)|(_|(_ |\                                             -- Joker
import java.io.*;
import java.net.*;

public class GetURL {
    public static void main(String[] args) throws Exception {
	InputStream in = null;
	OutputStream out = null;
	try {
	    if (!(args.length == 1 || args.length == 2))
		throw new IllegalArgumentException("Wrong number of args");

	    URL url = new URL(args[0]);
	    in = url.openStream();
	    if (args.length == 2)
		out = new FileOutputStream(args[1]);
	    else
		out = System.out;

	    byte[] buffer = new byte[4096];
	    int bytes_read;
	    while ((bytes_read = in.read(buffer)) != -1)
		out.write(buffer, 0, bytes_read);
	}
	catch (Exception e) {
	    System.err.println(e);
	}
	finally {
	    in.close();
	    out.close();
	}
    }
}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]