Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

CacheLoaderException when reading from cache and no loader factory is specified #28

Open
dzlab opened this issue Oct 30, 2014 · 6 comments
Assignees
Labels
Milestone

Comments

@dzlab
Copy link

dzlab commented Oct 30, 2014

I'm having the following exception when I read an entry that doesn't exist in the cache while I'm expecting a null. Do I have to provide a factory for the cache loader when I create the cache? currently I'm not.

javax.cache.integration.CacheLoaderException: java.lang.NullPointerException
    at org.ehcache.jcache.JCache.load(JCache.java:123)
    at org.ehcache.jcache.JCache.get(JCache.java:105)
        ...

Here is my configuration:

CompleteConfiguration<ComposedKey, Object> config1 = new MutableConfiguration<ComposedKey, Object>()
    // Configure the cache to be typesafe
        .setTypes(ComposedKey.class, Object.class)
        // Configure to expire entries 30 secs after creation in the cache
        .setExpiryPolicyFactory(FactoryBuilder.factoryOf(new AccessedExpiryPolicy(new Duration(TimeUnit.MINUTES, 30))))
        // Configure read-through of the underlying store
        .setReadThrough(true)
        // Configure write-through to the underlying store
        .setWriteThrough(true)
        // Configure the javax.cache.integration.CacheLoader
        // .setCacheLoaderFactory(FactoryBuilder.factoryOf(new UserCacheLoader(userDao)))
        // Configure the javax.cache.integration.CacheWriter
        // .setCacheWriterFactory(FactoryBuilder.factoryOf(new UserCacheWriter(userDao)))
        // Configure the javax.cache.event.CacheEntryListener with no
        // javax.cache.event.CacheEntryEventFilter, to include old value
        // and to be executed synchronously
        .addCacheEntryListenerConfiguration(
            new MutableCacheEntryListenerConfiguration<ComposedKey, Object>(new CacheListenerManagerJSR107Factory(), null, true,
                true));

It looks like when readTrough is set to true then a cache loader should be provided.

@alexsnaps
Copy link
Member

Well, I guess the NPE isn't the best option. But as the spec says (from the MutableConfiguration#setReadThrough Javadoc):

   * Set if read-through caching should be used.
   * <p>
   * It is an invalid configuration to set this to true without specifying a
   * {@link CacheLoader} {@link Factory}.

I guess the method you use to create the Cache should probably throw IllegalArgumentException (see CacheManager.createCache indeed. I'll fix that!

@alexsnaps alexsnaps self-assigned this Oct 31, 2014
@alexsnaps alexsnaps added this to the 1.0.1 milestone Oct 31, 2014
@alexsnaps alexsnaps added the Bug label Oct 31, 2014
@alexsnaps
Copy link
Member

Ugh! Looks like fixing this may be an issue... See the build for my PR #33
See jsr107/jsr107tck#59

@alexsnaps
Copy link
Member

Closed the initial PR and created a new one (PR #33) from my own fork this time... Still pending jsr107/jsr107tck#59 being fixed though!

@alexsnaps
Copy link
Member

Leaving this as targeted to 1.0.1 until the end of the week, if the EG on @jsr107 doesn't address jsr107/jsr107tck#59 by then, I'll have no other choice than postpone to 1.0.2

@alexsnaps alexsnaps modified the milestones: 1.1.0, 1.0.1 Dec 5, 2014
@alexsnaps
Copy link
Member

Post-poning, as it looks we won't be able to have the TCK fixed in time

@alexsnaps
Copy link
Member

Things have been changed around that in the TCK... Need to check if we need to upgrade to a newer version. And then let's fix this.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants