Bookmark Topic Watch Topic
  • New Topic

java.lang.StackOverflowError during Serialization  RSS feed

 
gov kur
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hello Once Again,
Thanks for responding David.
Like you said I declared the streams that threw the Serialization Exception as transient, but now it's throwing me a "java.lang.StackOverflowError" .
I tried increasing the size of the JVM by using -Xmx parameter but even then the actual size of the file written remained the same...so I guess that it's not something that just increasing the JVM size will help.

Please guide me on this ..
 
gov kur
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Report post to moderator
Oops ..
is it that increasing the JVM size only helps only the case of "OutOfMemoryException" and not in case of "StackOverflowException"
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Report post to moderator
It is possible that some of your objects refer recursively to one another, meaning that serialisation never ends.
 
gov kur
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Report post to moderator
hmm..... I'm pretty sure thats not the case. But even if it is of the form

public class A
{
B b1= new B();
public static void main(String[] args)
{
A a1=new A();
}
}
class B
{
A a2=new A();
}

This would give me an error during object creation itself.In my case I can create and work normally on the object ... it's only during Serialization that it gives me an Stack Overflow Error.
 
gov kur
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Report post to moderator
ok.... i tried to increase the stack size by using both

java -Xss128m file &&
java -Xoss128m file

However the file written to writes upto a particular size( in my case 3,189kb) and gives the Exception.

java.lang.StackOverflowError
at sun.misc.SoftCache.get(SoftCache.java:269)
at java.io.ObjectStreamClass.lookup(ObjectStreamClass.java:238)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1010)
at java.io.ObjectOutputStream.defaultWriteFields (ObjectOutputStream.java:1330)
at java.io.ObjectOutputStream.writeSerialData (ObjectOutputStream.java:1302)
at java.io.ObjectOutputStream.writeOrdinaryObject (ObjectOutputStream.java:1245)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1052)

The last 4 lines get repeated all over again..
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Report post to moderator
Is that your real code? Instantiating either an A or a B should cause a stack overflow, unless I'm missing something. Can you describe the graph of objects you're serializing?
 
gov kur
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Report post to moderator
sorry for that ..
the code posted above was my interpretation of what Stuart Gray meant.I was just trying to clarify it.

the actual code that i am working on is a legacy piece of C/C++ code that had been ported to java some years ago .It's actually responsible for conversions from English to the local Languages of my region.There are 2 stages to the conversion.

the first is where the rule files, the dictionay files etc(which are basically flat files) are read into instances of my own classes which are loaded by the Converter class.

the second stage is when i actually convert data using the Converter class which now has access to the above rules.

I've been trying to serialize my object after the first stage.

The problem is when i try to Serialize the object some of the flat files are read but the large flat files that contain the actual rules are copied to a certain extend before the "STACK OVERFLOW EXCEPTION" pops up.

I've made sure that there is no circular depenencies.
-----------------------------------
The link below is of a similar post so i was hoping that is a generic problem with large objects which need to be serialized

"http://www.coderanch.com/t/275875/Streams/java/StackOverflowError-serialization"
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Report post to moderator
Well, recursive references can be a lot more subtle than your example; I was thinking more of recursive field references than constructor calls. (e.g: A.field refers to B, and B.anotherfield refers to A).
 
gov kur
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Report post to moderator
Yeah sorry once again.. i got what you meant later on....

but should'nt the Serialization mechanism be able to handle it ?

I'd really appretiate some answers for this Stack Overflow error... Can u think of anything else that i can try out?
 
Joe Ess
Bartender
Posts: 9406
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Report post to moderator
This conversation is continued here
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!