Skip to content

Incorrect Rule: java/missing-no-arg-constructor-on-serializable  #18371

@ben-manes

Description

@ben-manes

* @name Serializable but no void constructor
* @description A non-serializable, immediate superclass of a serializable class that does not
* itself declare an accessible, no-argument constructor causes deserialization to
* fail.

This rule does not take into consideration the Serialization Proxy pattern. This approach is recommended in Effective Java, a reference this rule's explanation points to. The proxy pattern is both a simplification and protection from security threats by reconstructing the object from the data elements, using readResolve to replace the output with a new instance, rather than trying to rehydrate the object directly.

While ideally this rule would understand this pattern, it is okay if a false positive yet it recommends that as the solution. A less aware developer might remove this security protection to comply or not be nudged to implement that better approach if a true positive.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions