Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

ArrayList gives StackOverflowError in 1.5

Thread view: 
timjowers@gmail.com - 28 Nov 2005 13: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".

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)
Thomas Hawtin - 28 Nov 2005 14:22 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 - 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
Roedy Green - 28 Nov 2005 16:36 GMT
>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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.