If index = 80 and size = 100 then the condition will not evaluate to true, so the exception will not occur. So... perhaps index is not really 80 (e.g. maybe it's -80) or size is not really 100 (e.g. maybe it's 10) or your JVM has been hit by a stray cosmic ray. Or are you using it in a multi-threaded application? The methods in ArrayList are not synchronized, so it is possible (though you'd have to be reasonably unfortunate) that another thread updates the list at the same time as you're getting its contents. If this is the case, either synchronize or use a Vector instead.

Wang Yang
Greenhorn

Joined: Oct 11, 2002
Posts: 5

posted May 09, 2004 10:29:00

0

Originally posted by David Peterson:

If index = 80 and size = 100 then the condition will not evaluate to true, so the exception will not occur. So... perhaps index is not really 80 (e.g. maybe it's -80) or size is not really 100 (e.g. maybe it's 10) or your JVM has been hit by a stray cosmic ray. Or are you using it in a multi-threaded application? The methods in ArrayList are not synchronized, so it is possible (though you'd have to be reasonably unfortunate) that another thread updates the list at the same time as you're getting its contents. If this is the case, either synchronize or use a Vector instead.

Thank you every much! It is the trap of Multi-thread. I'll pay more attention to it.