0

While trying to serialize and deserialize object of java.time.Year, it gives serialization error and run into stackOverflow.

java.lang.StackOverflowError
    at com.caucho.hessian.util.IdentityIntMap.get(IdentityIntMap.java:112)
    at com.caucho.hessian.io.Hessian2Output.getRef(Hessian2Output.java:1359)
    at com.caucho.hessian.io.WriteReplaceSerializer.writeObject(WriteReplaceSerializer.java:144)
    at com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:465)
    at com.caucho.hessian.io.UnsafeSerializer$ObjectFieldSerializer.serialize(UnsafeSerializer.java:297)
    at com.caucho.hessian.io.UnsafeSerializer.writeInstance(UnsafeSerializer.java:216)
    at com.caucho.hessian.io.UnsafeSerializer.writeObject(UnsafeSerializer.java:170)

The sample code to reproduce this error is:

@Test
public void testHessianSerializeDeserialize() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    Hessian2Output out = new Hessian2Output(bos);

    out.startMessage();
    Year y1 = Year.of(2017);
    out.writeObject(y1);

    out.completeMessage();
    out.close();

    byte[] data = bos.toByteArray();

    // Deserialize
    ByteArrayInputStream bin = new ByteArrayInputStream(data);
    Hessian2Input in = new Hessian2Input(bin);

    in.startMessage();
    Assert.assertEquals(y1, (Year) in.readObject());

    in.completeMessage();
    in.close();
    bin.close();
}
P.J.Meisch
  • 18,013
  • 6
  • 50
  • 66
Sugan
  • 335
  • 3
  • 10

1 Answers1

0

Use of joda time 'Years' (org.joda.time.Years) instead of java.time.Year will not give the Hessian serialization and deserialization error.

Sugan
  • 335
  • 3
  • 10