harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wendy Feng (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-6652) Synchronized setter method but non-synchronized similarly-name getter method in DragSourceContextr.java
Date Sun, 19 Sep 2010 02:20:33 GMT
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.


Mime
View raw message