
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
55 lines
1.6 KiB
Plaintext
55 lines
1.6 KiB
Plaintext
== Why is this an issue?
|
|
|
|
In Records serialization is not done the same way as for ordinary serializable or externalizable classes. Records serialization does not rely on the ``++serialVersionUID++`` field, because the requirement to have this field equal is waived for record classes. By default, all records will have this field equal to ``++0L++`` and there is no need to specify this field with ``++0L++`` value and it is possible to specify it with some custom value to support serialization/deserialization involving ordinary classes.
|
|
|
|
|
|
This rule raises an issue when there is a ``++private static final long serialVersionUID++`` field which is set to ``++0L++`` in a Record class.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
record Person(String name, int age) implements Serializable {
|
|
@Serial
|
|
private static final long serialVersionUID = 0L; // Noncompliant
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
record Person(String name, int age) implements Serializable {} // Compliant
|
|
|
|
record Person(String name, int age) implements Serializable {
|
|
@Serial
|
|
private static final long serialVersionUID = 42L; // Compliant
|
|
}
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* https://docs.oracle.com/javase/specs/jls/se16/html/jls-8.html#jls-8.10[Records specification]
|
|
* https://docs.oracle.com/en/java/javase/16/docs/specs/serialization/serial-arch.html#serialization-of-records[Serialization of records]
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Remove this redundant "serialVersionUID" field
|
|
|
|
|
|
=== Highlighting
|
|
|
|
the 'serialVersionUID' field declaration
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|