You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Wendy Feng (JIRA)" <ji...@apache.org> on 2010/09/19 04:20:33 UTC

[jira] Created: (HARMONY-6652) Synchronized setter method but non-synchronized similarly-name getter method in DragSourceContextr.java

Synchronized setter method but non-synchronized similarly-name getter method in DragSourceContextr.java
-------------------------------------------------------------------------------------------------------

                 Key: HARMONY-6652
                 URL: https://issues.apache.org/jira/browse/HARMONY-6652
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
    Affects Versions: 6.0M1
         Environment: Windows XP
            Reporter: Wendy Feng


I found some unsafe synchronization in DragSourceContextr.java as follow:

public class DragSourceContext implements DragSourceListener,
        DragSourceMotionListener, Serializable{
...
public Cursor getCursor() {
        return cursor;
    }

    public synchronized void setCursor(Cursor c) {
        cursor = c;

        defaultCursor = (cursor == null);
        if (defaultCursor) {
            updateCurrentCursor(sourceAction, lastTargetAction, lastStatus);
        } 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.