Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8202416

ConcurrentHashMap.computeIfAbsent() contains a synchronization that has no effect

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Windows 7 Prof 64-bit

      A DESCRIPTION OF THE PROBLEM :
      The following code appears in the method:

                      ...
                      Node<K,V> r = new ReservationNode<K,V>();
                      synchronized (r) {
                          ...
                      }

      r contains a new instance r1 of ReservationNode created in the current thread T1. It is not possible for another thread T2 to see r1. Thus there can be no contention for r1 between T1 and T2. Synchronizing on (the contents of) a local variable cannot prevent concurrent access to the code in the synchronized block.

      It is reasonable to assume that the code author put this synchronization in to achieve a specific goal. Whatever the specific goal is, it cannot be achieved in this way.

      There is a similar synchronization on a local variable in ConcurrentHathMap.compute().

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Inspect the source.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Agreement that the synchronisation described has no effect, and may be evidence of a programming error.
      ACTUAL -
      The source inspected.

            dl Doug Lea
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: