Skip to content

[Bug] UnsafeDeserializer does not honor field default initializations #15750

@edoclin

Description

@edoclin

Pre-check

  • I am sure that all the content I provide is in English.

Search before asking

  • I had searched in the issues and found no similar issues.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

Apache dubbo: 3.3.4, java 8, hessian-lite 4.0.3

Steps to reproduce this issue

hessian-lite/src/main/java/com/alibaba/com/caucho/hessian/io/UnsafeDeserializer.java#instantiate
hessian-lite/src/main/java/com/alibaba/com/caucho/hessian/io/JavaDeserializer.java#instantiate

Migrating from dubbo2 to dubbo3, some entity classes still initialize default values, for example:

public class Example { private String all = "all"; }

UnsafeDeserializer constructs objects via allocateInstance; in certain scenarios, the deserialized object ends up with obj.all = null rather than the default obj.all = "all".

Using the startup parameter -Dcom.caucho.hessian.unsafe=false switches the deserializer to hessian-lite/src/main/java/com/alibaba/com/caucho/hessian/io/JavaDeserializer.java, which effectively solves the field default value issue.

However, when JavaDeserializer deserializes BigInteger with a null constructor argument, it throws an NPE (compared to dubbo2.7: com.alibaba.com.caucho.hessian.io.BigIntegerDeserializer provides a dedicated compatibility class).

Is there a method to make UnsafeDeserializer honor field default initializations, or a way to make JavaDeserializer compatible with BigInteger deserialization?

What you expected to happen

Provide a plan for ensuring deserialization compatibility during the migration process.

Anything else

No response

Are you willing to submit a pull request to fix on your own?

  • Yes I am willing to submit a pull request on my own!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedEverything needs help from contributorstype/discussionEverything related with code discussion or question

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions