Currently using the following...
remoteDataObject = <Remote call to get data>
synchronized(localDataObject)
{
localDataObject = remoteDataObject;
}
Coverity reports - Bad choice of lock object.
Bad choice of lock object (BAD_LOCK_OBJECT)7. lock_on_assigned_field: Locking on the object referenced by field localDataObject. This lock acquisition may race with another thread assigning to this field. The contents of localDataObject may change while a thread is inside the critical section, allowing two threads to enter the critical section simultaneously.
The only other reference to localDataObject is the retrieval.
public Vector <Obj1, Obj2> getLocalDataObjects ()
{
return localDataObject;
}
This isn't much different from how other objects are handled yet they don't return any Coverity issues.
In what scenario would a race condition occur?
How to resolve this Coverity error?