That’s all we can say right now.
This serializable class has a non-serializable superclass that does not declare a default constructor. Deserializing such a class will fail with an InvalidClassException
because Java will not be able to instantiate it.
Java's Serializable
interface enforces specific requirements on serializable classes that extend a non-serializable class:
To allow subtypes of non-serializable classes to be serialized, the subtype may assume responsibility for saving and restoring the state of the supertype's public, protected, and (if accessible) package fields. The subtype may assume this responsibility only if the class it extends has an accessible no-arg constructor to initialize the class's state. It is an error to declare a class
Serializable
if this is not the case. The error will be detected at runtime.
Put simply, given the following conditions:
Serializable
.Java will throw an InvalidClassException
when attempting to deserialize an instance of the class.
class SuperClass {
int x;
public SuperClass(int a) {
x = a;
}
}
// Java will fail to deserialize this class.
class SubClass extends SuperClass implements Serializable {
// ...
}
class SuperClass {
int x;
public SuperClass(int a) {
x = a;
}
public SuperClass() {
x = 0;
}
}
class SubClass extends SuperClass implements Serializable {
// ...
}