I have the following class signature and ClientEventSourc
implements Serializable
:
public class Grid extends ClientEventSource implements Focusable, FramingBlockWrapper,LIMSEditableField
Now FindBugs is listing this as dodgy :
Class is Serializable, but doesn't define serialVersionUID
This class implements the Serializable interface, but does not define a serialVersionUID field. A change as simple as adding a reference to a .class object will add synthetic fields to the class, which will unfortunately change the implicit serialVersionUID (e.g., adding a reference to String.class will generate a static field class$java$lang$String). Also, different source code to bytecode compilers may use different naming conventions for synthetic variables generated for references to class objects or inner classes. To ensure interoperability of Serializable across versions, consider adding an explicit serialVersionUID.
Can some explain what it means and what is the best possible way to fix this ?
the serialVersionUID is used to deserialize your class.
it is auto-generated by default.
but changing anything in your class would generate a different serialVersionUID and you cannot deserialise "old" objects.
so you define your own serialVersionUID to help deserialisation find the right class.
add a variable like this to your code:
private static final long serialVersionUID = 6106269076155338045L;
for reference on generating your UID:
Does it matter what I choose for serialVersionUID when extending Serializable classes in Java?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With