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

Possible race in FontDesignMetrics.KeyReference.dispose

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P5
    • Resolution: Fixed
    • Affects Version/s: 16, 17, 18
    • Fix Version/s: 18
    • Component/s: client-libs
    • Labels:
      None
    • Subcomponent:
      2d
    • Resolved In Build:
      b18

      Description

      Possible race condition could happen if another thread put value into 'metricsCache' by the same key.

              /* It is possible that since this reference object has been
              /* It is possible that since this reference object has been
               * enqueued, that a new metrics has been put into the table
               * enqueued, that a new metrics has been put into the table
               * for the same key value. So we'll test to see if the table maps
               * for the same key value. So we'll test to see if the table maps
               * to THIS reference. If its a new one, we'll leave it alone.
               * to THIS reference. If it's a new one, we'll leave it alone.
               * It is possible that a new entry comes in after our test, but
               * it is unlikely and if this were a problem we would need to
               * synchronize all 'put' and 'remove' accesses to the cache which
               * I would prefer not to do.
               */
               */
              public void dispose() {
              public void dispose() {
                  if (metricsCache.get(key) == this) {
                  metricsCache.remove(key, this);
                      metricsCache.remove(key);
                  }
              }

      We can use `ConcurrentHashMap.remove(key, value)` method to avoid it.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              aturbanov Andrey Turbanov
              Reporter:
              aturbanov Andrey Turbanov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: