ArrayList gives StackOverflowError in 1.5

T

timjowers

Someone else asked this in April but groups.google.com does not allow
me to reply to it: "JDK 1.4 to 1.5 StackOverFlowError".

Running under 1.5 I receive a StackOverFlowException when serializing
to disk ~10-100k of objects in a hierarchy with the nodes saved in
ArrayLists. I can try -Xss but has anyone else seen and fixed this
problem? Is all Java serialization stack-size inhibited or does
ArrayList specially impose this restriction in its implementation of
writeObject?

Thanks!
TimJowers

Exception in thread "main" java.lang.StackOverflowError
at sun.misc.SoftCache.processQueue(SoftCache.java:153)
at sun.misc.SoftCache.get(SoftCache.java:269)
at java.io_ObjectStreamClass.lookup(ObjectStreamClass.java:244)
at
java.io_ObjectOutputStream.writeObject0(ObjectOutputStream.java:1029)
at
java.io_ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
at
java.io_ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
at
java.io_ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
at
java.io_ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
at java.io_ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
at java.util.ArrayList.writeObject(ArrayList.java:570)
at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
java.io_ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:890)
at
java.io_ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1333)
at
java.io_ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
at
java.io_ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
at
java.io_ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
at
java.io_ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
at
java.io_ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
at
java.io_ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
at java.io_ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
at java.util.ArrayList.writeObject(ArrayList.java:570)
at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
java.io_ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:890)
at
java.io_ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1333)
at
java.io_ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
at
java.io_ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
at
java.io_ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
at
java.io_ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
at
java.io_ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
at
java.io_ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
at java.io_ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
at java.util.ArrayList.writeObject(ArrayList.java:570)
at sun.reflect.GeneratedMethodAccessor14.invoke(Unknown Source)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at
java.io_ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:890)
at
java.io_ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1333)
... hundreds of lines duplicating those above ....
at java.lang.reflect.Method.invoke(Method.java:585)
at
java.io_ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:890)
at
java.io_ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1333)
at
java.io_ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
at
java.io_ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
at
java.io_ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1369)
at
java.io_ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1341)
at
java.io_ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
at
java.io_ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
at java.io_ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
at java.util.ArrayList.writeObject(ArrayList.java:570)
 
T

Thomas Hawtin

Someone else asked this in April but groups.google.com does not allow
me to reply to it: "JDK 1.4 to 1.5 StackOverFlowError".

Running under 1.5 I receive a StackOverFlowException when serializing
to disk ~10-100k of objects in a hierarchy with the nodes saved in
ArrayLists. I can try -Xss but has anyone else seen and fixed this
problem? Is all Java serialization stack-size inhibited or does
ArrayList specially impose this restriction in its implementation of
writeObject?

Looks like a very deep hierarchy.

If you don't have troublesome cycles, you might be able to fudge it by
leading with a discardable array list containing nodes in an order such
that they only refer to previously referenced nodes. So to create the
list, traverse the hierarchy in a conventional manner, adding a node
when all of its child nodes have already been added.

Tom Hawtin
 
R

Robert Klemme

Thomas said:
Looks like a very deep hierarchy.

If you don't have troublesome cycles, you might be able to fudge it by
leading with a discardable array list containing nodes in an order
such that they only refer to previously referenced nodes. So to
create the list, traverse the hierarchy in a conventional manner,
adding a node when all of its child nodes have already been added.

I'm surprised how fast Java fails (note, this test done with Java 1.4.2):
Error when nesting=491

Test program:

package serialization;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io_ObjectOutputStream;
import java.util.ArrayList;

public class NestingTest {

public static void main( String[] args ) throws IOException,
ClassNotFoundException {
int nesting = 1;

try {
while ( true ) {
ArrayList root = new ArrayList( 1 );
ArrayList node = root;

for ( int i = 0; i < nesting; ++i ) {
ArrayList tmp = new ArrayList( 1 );
node.add( tmp );
node = tmp;
}

ByteArrayOutputStream byteOut = new
ByteArrayOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(
byteOut );
objOut.writeObject( root );
objOut.close();

++nesting;
}
} catch ( StackOverflowError e ) {
System.out.println( "Error when nesting=" + nesting );
}
}
}


Kind regards

robert
 
R

Roedy Green

Running under 1.5 I receive a StackOverFlowException when serializing
to disk ~10-100k of objects in a hierarchy with the nodes saved in
ArrayLists. I can try -Xss but has anyone else seen and fixed this
problem? Is all Java serialization stack-size inhibited or does
ArrayList specially impose this restriction in its implementation of
writeObject?
It used to overflow at about 1000 objects.

StackOverflow suggests the recursion process to chase links is the
problem. You have huge long chains of objects.

If you wanted to drive writeObject insane, the easiest way to do it
would be to have single chain running through all 100K objects.

If the subtrees are not interlinked, you also might look at saving the
subtrees individually, perhaps even calling reset after each subtree.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top