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

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:

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.

Environment

None

Activity

Show:
Sean Corfield
January 6, 2019, 10:33 PM

Will be in 0.7.2

Completed

Assignee

Sean Corfield

Reporter

import

Labels

None

Approval

None

Patch

Code and Test

Priority

Minor