Search code examples
javafieldserialversionuidsynthetic

Why would the Java compiler create a serialVersionUID synthetic field?


As part of debugging an application, I noticed that Field.getDeclaredFields() returns some synthetic fields, including a serialVersionUID field in a class extending an interface, although none extend Serializable.

Why does the compiler add such fields?

UPDATE

In fact, there is also a $VRc synthetic field created.


Solution

  • The Java compiler/runtime will not automatically create a serialVersionUID field. I suspect that you are using some form of bytecode enchancement framework under the hood that is being instructed to add the synthetic fields either at runtime, or during compilation.

    The $VRc field is produced by the Emma instrumentation framework, so that would be the reason for at least one of the synthetic fields.

    The serialVersionUID field is also added by Emma, when the instr.do_suid_compensation property is set to true.