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

Possible race in FontDesignMetrics.KeyReference.dispose

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 18
    • 16, 17, 18
    • client-libs
    • None
    • 2d
    • b18

      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.

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

              Created:
              Updated:
              Resolved: