Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt in StackOverflowError

 
Abhijit Das
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I am getting error as follows :
I am showing a part of it.
My program is
The error is coming in the "out.writeObject(objClone);"
Can give any idea about the error. My objClone is a object of a class.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49466
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I don't think that is the location of the error. Something is duplicating itself; it might be to do with the cloning.
You need to go up and down the stack trace and see what you can find.
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the class definition (without methods, just the fields) of objClone? Because it does seem to be related to that class, and how it is serialized. Also include any methods regarding serializing: readObject, writeObject, etc.
 
Abhijit Das
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello Ritchie,
I am not getting your explanation. Now I am sending the function.


My Ooutput is



thanks Abhijit
[ September 17, 2008: Message edited by: Rob Prime ]
 
Abhijit Das
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Prime,

I just send the class whose object is being passed in the function when I called the given function[public static Object deepClone(Object objClone)]. That is, objClone is the object of TemplateComponent. The function is given in last post.The class with fields only is
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So that's two Rectangles and one int. The rest is either static or transient and therefore will not be serialized.

However, this class is abstract, and it cannot be instantiated. The actual class, and any class between the actual class and TemplateComponent, may also add fields. Perhaps some of those are causing the problem.
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, I've been diving into the Java code (with thanks to JAD), and I just can't see why you are getting this error.

A StackOverflowError is thrown when using a recursive method in over 90% of the cases. However, neither sun.misc.SoftCache#get nor sun.misc.SoftCache#processQueue is recursive. processQueue does have a loop, but that shouldn't throw that error. It does call some methods of a ReferenceQueue (poll) and a SoftReference sub class, but that too should not cause this error.


To be frank, I'm quite puzzled.
 
Abhijit Das
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Prime,
The object 'TemplateComponent' is obtained from other getter method of a class.
The problem is that 'StackOverflowError' is not coming for simple senerio.For the complex case only the error is occuring.

Ok, thanks for replying.....
Yes, it is little bit confusing by showing a bit of code here only. Because there are lots of intermediate classes in the applicaation.

 
Abhijit Das
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

hi,

Through out the serialization, there are four classes having different class instance variables in the hierarchical order. There are some non-static and non-transient variables in the classes. So, I make transient for them . Now i am get the proper output.

I like to know that is there any other impact in my application by declaring the variable as transient?

AS I solved the problem by using this, now is it will reflect for other cases too? Because I am using a big application , I do not know any problem of declaring the variables as transient type.
As far my knowledge , the transient will be used for not to serialized the variable.

thank Prime for the suggestion.


Thanks
abhijit
 
Rob Spoor
Sheriff
Pie
Posts: 20555
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Abhijit Das:
I like to know that is there any other impact in my application by declaring the variable as transient?

Well, the value will get a default value (null for objects) if you deserialize it again. You can reinitialize it using the readObject method, or when you need it:


As far my knowledge , the transient will be used for not to serialized the variable.

Correct, that's the only use for transient.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic