Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
6.0M1
-
None
-
None
-
Windows XP
Description
I found some unsafe synchronization in DragSourceContextr.java as follow:
public class DragSourceContext implements DragSourceListener,
DragSourceMotionListener, Serializable{
...
public Cursor getCursor()
public synchronized void setCursor(Cursor c) {
cursor = c;
defaultCursor = (cursor == null);
if (defaultCursor)
else
{ peer.setCursor(cursor); } }
...
}
in the above code, cursor is a field variable but not declared volatile. getCursor() method is not synchronized while setCursor(Cursor c) is. Unless the fields are declared volatile, the Java Memory Model doesn't guarantee up-to-date field value visible to threads in the absent of synchronization. Caller of unsynchronized getter method could read stale or inconsistent values, which could cause serious problems.
Consequence:
Threads can read a stale cursor value in the absence of synchronization.
It is more safer to Synchronize getScheduledExecutionTime() method.