Why is this an issue?
A readObject
method is written when a Serializable
object needs special handling to be rehydrated from file. It should be
the case that the object being created by readObject
is only visible to the thread that invoked the method, and the
synchronized
keyword is not needed, and using synchronized
anyway is just confusing. If this is not the case, the method
should be refactored to make it the case.
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
//...
}