Skip to content

BoundedLocalCache throws NPE on Shutdown if CacheLoader returns a null. #35

@tellisnz

Description

@tellisnz

This:

    @Test
    public void throwsNullPointerException() {
        LoadingCache<String, Object> cache = Caffeine.newBuilder()
                .maximumSize(10000)
                .build(key -> null);
        cache.get("NullKey");
    }

Throws:

Exception in thread "ForkJoinPool.commonPool-worker-1" java.lang.NullPointerException
    at com.github.benmanes.caffeine.cache.BoundedLocalCache$RemovalTask.run(BoundedLocalCache.java:1131)
    at com.github.benmanes.caffeine.cache.BoundedLocalCache.drainWriteBuffer(BoundedLocalCache.java:1025)
    at com.github.benmanes.caffeine.cache.BoundedLocalCache.maintenance(BoundedLocalCache.java:904)
    at com.github.benmanes.caffeine.cache.BoundedLocalCache.cleanUp(BoundedLocalCache.java:888)
    at com.github.benmanes.caffeine.cache.BoundedLocalCache$$Lambda$4/1020154737.run(Unknown Source)
    at java.util.concurrent.ForkJoinTask$RunnableExecuDisconnected from the target VM, address: '127.0.0.1:49629', transport: 'socket'
teAction.exec(ForkJoinTask.java:1402)

on shutdown. Is this desired behaviour or have I done something wrong above?

compile 'com.github.ben-manes.caffeine:caffeine:2.0.1'

Should the check on BondedLocalCache line 1812:

    if (node == null) {
      afterWrite(null, new RemovalTask(removed[0]), now);
      return null;
    }

maybe include removed[0] not being null? I.e.

    if (node == null && removed[0] != null) {
      afterWrite(null, new RemovalTask(removed[0]), now);
      return null;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions