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

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 6.0M1
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None
    • Environment:
      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

            • Assignee:
              Unassigned
              Reporter:
              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