[kaffe] RandomAccessFile causes StackOverflowError
Dalibor Topic
robilad at yahoo.com
Wed Apr 2 03:27:01 PST 2003
Hi Ito,
--- Ito Kazumitsu <ito.kazumitsu at hitachi-cable.co.jp>
wrote:
>
> In message "Re: [kaffe] RandomAccessFile causes
> StackOverflowError"
> on 03/03/28, Ito Kazumitsu
> <ito.kazumitsu at hitachi-cable.co.jp> writes:
>
> > > The attached program causes StackOverflowError
> when run with
> > > kaffe
>
> > And here is a patch.
>
> The problem is simple.
>
> The attached programs go into an infinite loop as is
> easily seen.
> And kaffe's read() of java.io.RandomAccessFile and
> some others
> have the same kind of bug.
that made it much clearer, thanks.
So in short, the problem is that some IO classes
implement read() or read(char/byte[]) by delegating it
directly to read(char/byte[], int, int) which can be
reimplemented in a subclass to call read() or
read(char/byte []), resulting in a circular sequence
of calls blowing up the stack eventually.
You patch elegantly solves the issue by delegating to
an internal worker method _read(char/byte[], int,
int). I'll check it in tonight.
It would be great if you could review other IO code
and
send me the patches.
In general, the problem can be summed up as:
method M is implemented using overwriteable method N.
Since there is no way to guarantee that N won't be
overwritten to utilize M, the safest way to implement
M and N is to delegate their calls to a private worker
method implementation N' .
I bet there is a lot of code out there that suffers
from this problem ;)
I'm wondering how to write a program that
automatically tests for this bug pattern ... Or is
there some static checker out there that can do this
already?
I've attached some hand written tests as a start. They
have both discovered new bugs.
cheers,
dalibor topic
__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CircularDelegation.java
Type: text/x-java
Size: 2357 bytes
Desc: CircularDelegation.java
Url : http://kaffe.org/pipermail/kaffe/attachments/20030402/bb28845c/attachment-0006.java
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CircularDelegation2.java
Type: text/x-java
Size: 1779 bytes
Desc: CircularDelegation2.java
Url : http://kaffe.org/pipermail/kaffe/attachments/20030402/bb28845c/attachment-0007.java
More information about the kaffe
mailing list