Christian Asmussen <[EMAIL PROTECTED]> writes:
> On 16 Feb 2002, Jason van Zyl wrote:
>
>> On Sat, 2002-02-16 at 14:05, Christian Asmussen wrote:
>> > I got across a problem, and would like to know if you guys have a formal
>> > way of dealing with it. Supose we have the following recursive method
>> >
>> > public int getDepth(){
>> > return getParent() == null ? 0 : getParent().getDepth() + 1;
>> > }
>> >
>> >
>> > If an interface disigner creates an object with "setParent(this)" then
>> > getDepth would cause an infinite loop. Depending on the method, this
>> > could cause a whole server to go OOME. Whats the best for to deal whit
>> > this? I thought of three ways of avoiding it. What's the best one?
>>
>> If in this particular case you required an acyclic graph of objects then
>> you could either use something like a class invariant or an assertion to
>> make sure that the parameter to setParent(Object o) isn't itself.
>
> But what if the guy goes getParent().setParent(this); or more? Ooops you
> sayd acyclic right ;-) But I assume it is the developers task to avoid
> this right?
An IllegalArgumentException or subclass could be thrown. Submit a
patch:
http://jakarta.apache.org/site/source.html
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>