Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-6652

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 6.0M1
    • None
    • Classlib
    • None
    • Windows XP

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            cashcrop Wendy Feng
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 3h
                3h
                Remaining:
                Remaining Estimate - 3h
                3h
                Logged:
                Time Spent - Not Specified
                Not Specified