Uploaded image for project: 'core.cache'
  1. CCACHE-52

SoftCache can cause an NPE if reference has been queued before eviction

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Completed
    • Labels:
      None
    • Patch:
      Code and Test

      Description

      While using the SoftCache we found a NullPointerException could occur while attempting to clear the cache of any enqueued references. We think this is because the references had been enqueued (presumably as a result of GC) before being evicted. In our case the SoftCache is being used as a base for a TTLCacheQ.

      The (slightly reduced) stack-trace is as follows:

      java.lang.NullPointerException: null
      	at java.util.concurrent.ConcurrentHashMap.replaceNode(ConcurrentHashMap.java:1106)
      	at java.util.concurrent.ConcurrentHashMap.remove(ConcurrentHashMap.java:1097)
      	at clojure.core.cache$clear_soft_cache_BANG_.invokeStatic(cache.clj:512)
      	at clojure.core.cache$clear_soft_cache_BANG_.invoke(cache.clj:509)
      	at clojure.core.cache.SoftCache.evict(cache.clj:558)
      	at clojure.core.cache.SoftCache.without(cache.clj:521)
      	at clojure.lang.RT.dissoc(RT.java:884)
      	at clojure.core$dissoc.invokeStatic(core.clj:1503)
      	at clojure.core$dissoc.invoke(core.clj:1496)
              ...
      

      The exception is thrown in ConcurrentHashMap when attempting to get the hash-code of the key we're removing but since that key is null the call fails.

      I have included a test which causes the same exception and a defensive fix which prevents the exception by not attempting to remove from cache unless we have found the corresponding item in rcache.

        Attachments

          Activity

            People

            • Assignee:
              seancorfield Sean Corfield
              Reporter:
              alex+import import
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: