Inspectopedia Help

'@Serial' annotation used on wrong member

Reports methods and fields in the Serializable and Externalizable classes that are not suitable to be annotated with the java.io.Serial annotation.

Examples:

class Test implements Serializable { @Serial // The annotated field is not a part of serialization mechanism because it's not final private static long serialVersionUID = 7874493593505141603L; @Serial // The annotated method is not a part of the serialization mechanism because it's not private void writeObject(ObjectOutputStream out) throws IOException { } }
class Test implements Externalizable { @Serial // The annotated method is not a part of the serialization mechanism as it's inside Externalizable class private void writeObject(ObjectOutputStream out) throws IOException { } }

For information about all valid cases, refer the documentation for java.io.Serial.

Locating this inspection

By ID

Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.

SerialAnnotationUsedOnWrongMember
Via Settings dialog

Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.

Settings or Preferences | Editor | Inspections | Java | Serialization issues

This inspection depends on the Java feature '@Serial annotation' which is available since Java 14.

New in 2020.3

Availability

By default bundled with

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin

Java, 241.18072

Last modified: 18 June 2024