I think we may have found the cause of an OutOfMemoryError that has been troubling us for some time.
Today we tracked it down to a one-to-many mapping using a List with an index. It would appear that the error was triggered because the value of the index was very large.
Consider the following code in net.sf.hibernate.collection.List:
/**
* @see PersistentCollection#readFrom(ResultSet, CollectionPersister)
*/
public Object readFrom(ResultSet rs, CollectionPersister persister, Object owner)
throws HibernateException, SQLException {
Object element = persister.readElement(rs, owner, session) ;
int index = ( (Integer) persister.readIndex(rs, session) ).intValue();
for ( int i = list.size(); i<=index; i++) {
list.add(i, null);
}
list.set(index, element);
return element;
}
If index is a very large value, say 10,000,000 and the size of the list is small, then a very large number of elements will be added to the list.
Now I am wondering what the purpose of this code is? What is the intent? Is this a bug?
I our case we were able to get around the problem by changing the mapping to not use an index. However, it still looks like a bug to me.
|