The readObject
method is implemented when a Serializable
object requires special handling to be reconstructed from a
file. The object created by readObject
is accessed only by the thread that called the method, thus using the synchronized
keyword in this context is unnecessary and causes confusion.
Noncompliant code example
private synchronized void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException { // Noncompliant
//...
}
Compliant solution
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException { // Compliant
//...
}