wood burning stoves 2.0*
The moose likes Java in General and the fly likes Doubt in StackOverflowError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Doubt in StackOverflowError" Watch "Doubt in StackOverflowError" New topic
Author

Doubt in StackOverflowError

Abhijit Das
Ranch Hand

Joined: Sep 25, 2007
Posts: 156
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.


Abhijit Das
SCJP 5.0 | SCWCD 1.5
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
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

Joined: Oct 27, 2005
Posts: 19541
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Abhijit Das
Ranch Hand

Joined: Sep 25, 2007
Posts: 156
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

Joined: Sep 25, 2007
Posts: 156
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

Joined: Oct 27, 2005
Posts: 19541
    
  16

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

Joined: Oct 27, 2005
Posts: 19541
    
  16

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

Joined: Sep 25, 2007
Posts: 156
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

Joined: Sep 25, 2007
Posts: 156
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

Joined: Oct 27, 2005
Posts: 19541
    
  16

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt in StackOverflowError
 
Similar Threads
java.io. NotSerializableException: java.awt.TexturePaint
Serialization issue
Testing serialization performance
class not found exception in applet servlet communication
Does the order of stream closing matters?