[kaffe] RandomAccessFile causes StackOverflowError

Ito Kazumitsu ito.kazumitsu at hitachi-cable.co.jp
Thu Mar 27 19:10:01 PST 2003


The attached program causes StackOverflowError when run with
kaffe (Version: 1.1.x-cvs,
 ChangeLog head: 2003-03-14 Tim Stack <stack at cs.utah.edu>).

     Compiler     JVM              Result
     --------     --------------   ----------------------
     kjc          kaffe            StackOverflowError
     kjc          J2SDK 1.4.1_02   OK
     Sun's javac  J2SDK 1.4.1_02   OK

The attached program was copied from org/hsqldb/DatabaseFile.java
of http://cvs.sourceforge.net/cvstarballs/hsqldb-cvsroot.tar.gz
(HSQLDB of version under development) and simplified for testing.

Here is the program.

import java.io.RandomAccessFile;
import java.io.IOException;
import java.io.FileNotFoundException;

class TestRandomAccessFile extends RandomAccessFile {

    protected byte in[];
    protected int  index;
    protected int  count;

    public static void main(String[] args) throws Exception {
       TestRandomAccessFile f = new TestRandomAccessFile(args[0], "r",256);
       byte[] buf = new byte[1024];
       while (true) {
           int l = f.read(buf,0,buf.length);
           if (l == -1) break;
       } 
    }

    TestRandomAccessFile(String name, String mode,
                 int inSize) throws FileNotFoundException, IOException {

        super(name, mode);

        in       = new byte[inSize];
    }

   public int read() throws IOException {

        if (in == null) {
            return (super.read());
        }

        if (index == count) {
            index = 0;
            System.err.println("count = super.read(in)"); System.err.flush();
            count = super.read(in);
            System.err.println(count); System.err.flush();

            if (count == -1) {
                count = 0;
            }
        }

        if (index == count) {
            return (-1);
        }

        return (in[index++] & 0xff);
    }

    public int read(byte[] b, int offset, int length) throws IOException {

        int i = 0;
        int next;

        for (; i < length; i++) {
            System.err.println("next = read()"); System.err.flush();
            next = read();
            System.err.println("next="+next); System.err.flush();

            if (next == -1) {
                return (-1);
            }

            b[offset + i] = (byte) next;
        }

        return i;
    }
}




More information about the kaffe mailing list