> 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".
[quoted text clipped - 5 lines]
> 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

Signature
Unemployed English Java programmer
http://jroller.com/page/tackline/
Robert Klemme - 28 Nov 2005 14:56 GMT
>> 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".
[quoted text clipped - 13 lines]
> 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
>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.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.