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

Error creating caches with a TTL #48

Open
igmar opened this issue Jun 4, 2015 · 5 comments
Open

Error creating caches with a TTL #48

igmar opened this issue Jun 4, 2015 · 5 comments
Assignees
Milestone

Comments

@igmar
Copy link

igmar commented Jun 4, 2015

This works :

JCacheConfiguration jCacheConfiguration = new JCacheConfiguration(null, null, null, null);
cache = cacheManager.createCache(this.name, jCacheConfiguration);

while this gives me a NPE :

CacheConfiguration cacheConfiguration = new CacheConfiguration();
cacheConfiguration.setTimeToLiveSeconds(NO_EXPIRE);
cacheConfiguration.setTimeToIdleSeconds(NO_EXPIRE);
JCacheConfiguration jCacheConfiguration = new JCacheConfiguration(cacheConfiguration);
cache = cacheManager.createCache(this.name, jCacheConfiguration);

where NO_EXPIRE is equal to 60 * 60 * 24 * 365 * 10

The only difference I see on code paths is that the second doesn't set an expire factory, while the first path does.

@alexsnaps alexsnaps added this to the 1.0.2 milestone Jul 31, 2015
@alexsnaps alexsnaps self-assigned this Jul 31, 2015
@alexsnaps
Copy link
Member

I wrote this small test:

    javax.cache.CacheManager cacheManager = Caching.getCachingProvider().getCacheManager();
    CacheConfiguration cacheConfiguration = new CacheConfiguration();
    cacheConfiguration.setTimeToLiveSeconds(60 * 60 * 24 * 365 * 10);
    cacheConfiguration.setTimeToIdleSeconds(60 * 60 * 24 * 365 * 10);
    JCacheConfiguration jCacheConfiguration = new JCacheConfiguration(cacheConfiguration);
    javax.cache.Cache cache = cacheManager.createCache("boo", jCacheConfiguration);
    cache.put("key", "Value");
    assertThat(cache.get("key"), is((Object) "Value"));

And nothing fails... Not sure what NPE you see @igmar , could you share it?

@igmar
Copy link
Author

igmar commented Aug 6, 2015

I'll check when I get back from holiday. No usable laptop with me.

@igmar
Copy link
Author

igmar commented Jun 10, 2016

To bring this back up :

Error in custom provider, java.lang.NullPointerException
at com.bm.common.cache.CacheModule$1.configure(CacheModule.java:78) (via modules: com.google.inject.util.Modules$OverrideModule -> com.bm.common.cache.CacheModule -> com.bm.common.cache.CacheModule$1)
at com.bm.common.cache.CacheModule$1.configure(CacheModule.java:78) (via modules: com.google.inject.util.Modules$OverrideModule -> com.bm.common.cache.CacheModule -> com.bm.common.cache.CacheModule$1)
while locating javax.cache.Cache annotated with @com.bm.common.cache.ehcache.EHCache(value=games)
for field at cache.CacheTest.cache(CacheTest.java:40)
while locating cache.CacheTest

1 error

at com.google.inject.internal.Errors.throwProvisionExceptionIfErrorsExist(Errors.java:482)
at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:67)
at com.google.inject.internal.InjectorImpl.injectMembers(InjectorImpl.java:984)
at cache.CacheTest.cacheEmpty(CacheTest.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:119)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:234)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Caused by: java.lang.NullPointerException
at org.ehcache.jcache.JCacheConfiguration.(JCacheConfiguration.java:67)
at org.ehcache.jcache.JCacheConfiguration.(JCacheConfiguration.java:124)
at org.ehcache.jcache.JCacheManager.createCache(JCacheManager.java:110)
at com.bm.common.cache.ehcache.EHCacheProvider.get(EHCacheProvider.java:41)
at com.bm.common.cache.ehcache.EHCacheProvider.get(EHCacheProvider.java:18)
at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision(InternalFactoryToInitializableAdapter.java:53)
at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(InternalFactoryToInitializableAdapter.java:45)
at com.google.inject.internal.ProviderToInternalFactoryAdapter$1.call(ProviderToInternalFactoryAdapter.java:46)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1103)
at com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)
at com.google.inject.internal.SingletonScope$1.get(SingletonScope.java:145)
at com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)
at com.google.inject.internal.ExposedKeyFactory.get(ExposedKeyFactory.java:54)
at com.google.inject.internal.SingleFieldInjector.inject(SingleFieldInjector.java:54)
at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:132)
at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:93)
at com.google.inject.internal.MembersInjectorImpl$1.call(MembersInjectorImpl.java:80)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)
at com.google.inject.internal.MembersInjectorImpl.injectAndNotify(MembersInjectorImpl.java:80)
at com.google.inject.internal.MembersInjectorImpl.injectMembers(MembersInjectorImpl.java:62)
... 30 more

@igmar
Copy link
Author

igmar commented Jun 10, 2016

I'll also do some diving, to see if I can figure out what causes this. It's a DI usage, in the Play framework in case it's relevant.

@igmar
Copy link
Author

igmar commented Jun 10, 2016

It blows up in JCacheConfiguration.java :

Factory expiryPolicyFactory = cConfiguration.getExpiryPolicyFactory();
this.expiryPolicy = expiryPolicyFactory.create();

expiryPolicyFactory is null -> kaboom. No idea yet as to why.

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

No branches or pull requests

2 participants