[Kaffe] bug in InputStream.available() method

Moses DeJong dejong at cs.umn.edu
Sat Dec 26 19:57:26 PST 1998


Here is a simple "echo" type of program that fails under
kaffe (off a fresh CVS tree). The System.in.available()
method seems to be returning -1 when there are 0 bytes
available. This same code works just find under a Sun JDK.
I was running under solaris-sparc2.6 and I compiled with gcc.


public class echo {
    public static void main(String[] argv) throws Exception {
	System.out.println("Please begin typing");
	
	while (true) {

	    int avail = System.in.available();

	    if (avail == 0) {
		Thread.currentThread().sleep(100);
	    } else {
		byte[] buff = new byte[avail];
		System.in.read(buff);
		
		//echo back what was just typed
		System.out.println();
		System.out.println("-----ECHO BEGIN-----");
		System.out.write(buff);
		System.out.println("-----ECHO END-----");
	    }
	}
    }
}


mo(/tmp/mo/kaffe_bug)% /tmp/mo/install_kaffe/bin/kaffe echo
Please begin typing
java.lang.NegativeArraySizeException
        at echo.main(13)


I hope that helps
Mo DeJong
dejong at cs.umn.edu



More information about the kaffe mailing list