Mantis - Hessian
Viewing Issue Advanced Details
6392 minor always 04-16-21 06:23 10-30-23 02:24
garsonchan  
 
normal  
new 4.0.63  
open  
none    
none  
0006392: Hessian can not support a class with a filed which is LocalDate when serializing
We get an "StackOverflow Exception" while trying to serialize a class with a field which is LocalDate.

We create a small testcase to reproduce the bug. The testcase uses JavaSerializer and Hessian2Output to serialize a class A, which has a field called a_filed.

We finally find that JavaSerializer would use java.time.LocalDate#writeReplace to serialize LocalDate,which returns an object of java.time.Ser.The class of java.time.Ser has a field ,which is the object of LocalDate that class A has(a_filed).
So when JavaSerializer serialzes class A, it would use writeObject and cause an endless loop between serialzing a_filed and the object of java.time.Ser that java.time.LocalDate#writeReplace returns.
The Exception stack is below:
Exception in thread "main" java.lang.StackOverflowError
    at com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:260)
    at com.caucho.hessian.io.SerializerFactory.getObjectSerializer(SerializerFactory.java:217)
    at com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:463)
    at com.caucho.hessian.io.UnsafeSerializer$ObjectFieldSerializer.serialize(UnsafeSerializer.java:299)
    at com.caucho.hessian.io.UnsafeSerializer.writeInstance(UnsafeSerializer.java:218)
    at com.caucho.hessian.io.UnsafeSerializer.writeObject(UnsafeSerializer.java:172)
    at com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:465)
    at com.caucho.hessian.io.WriteReplaceSerializer.writeObject(WriteReplaceSerializer.java:167)
    at com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:465)
    at com.caucho.hessian.io.UnsafeSerializer$ObjectFieldSerializer.serialize(UnsafeSerializer.java:299)
    at com.caucho.hessian.io.UnsafeSerializer.writeInstance(UnsafeSerializer.java:218)
    at com.caucho.hessian.io.UnsafeSerializer.writeObject(UnsafeSerializer.java:172)
    at com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:465)
    at com.caucho.hessian.io.WriteReplaceSerializer.writeObject(WriteReplaceSerializer.java:167)
    at com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:465)
    at com.caucho.hessian.io.UnsafeSerializer$ObjectFieldSerializer.serialize(UnsafeSerializer.java:299)
...
 A.java [^] (607 bytes) 04-16-21 06:23

There are no notes attached to this issue.