Uploaded image for project: 'Code Tools'
  1. Code Tools
  2. CODETOOLS-7098395

FindBugs: Synchronization on field in futile attempt to guard that field

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • jt4.4.1
    • jt4.4.1
    • tools
    • b05
    • b05
    • generic
    • generic
    • Verified

      ML: Synchronization on field in futile attempt to guard that field (ML_SYNC_ON_FIELD_TO_GUARD_CHANGING_THAT_FIELD)

      This method synchronizes on a field in what appears to be an attempt to guard against simultaneous updates to that field. But guarding a field gets a lock on the referenced object, not on the field. This may not provide the mutual exclusion you need, and other threads might be obtaining locks on the referenced objects (for other purposes). An example of this pattern would be:

      private Long myNtfSeqNbrCounter = new Long(0);
      private Long getNotificationSequenceNumber() {
           Long result = null;
           synchronized(myNtfSeqNbrCounter) {
               result = new Long(myNtfSeqNbrCounter.longValue() + 1);
               myNtfSeqNbrCounter = new Long(result.longValue());
           }
           return result;
       }


      ML: In class com.sun.javatest.exec.ProgressMeter
      In class com.sun.javatest.exec.ProgressMeter
      In method com.sun.javatest.exec.ProgressMeter.stop()
      Field com.sun.javatest.exec.ProgressMeter.myThread
      At ProgressMeter.java:[line 135]
      Synchronization on ProgressMeter.myThread in futile attempt to guard it

            ersh Mikhail Ershov (Inactive)
            ersh Mikhail Ershov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: