• Bug
  • Status: Closed
  • 2 Major
  • Resolution: Fixed
  • ehcache-core
  • cdennis
  • Reporter: bromberg
  • March 01, 2012
  • 0
  • Watchers: 4
  • July 27, 2012
  • March 02, 2012



we get a NPE when creating a new cache.

I looks like the Bug is in this Method: String[] net.sf.ehcache.CacheManager.getCacheNames() throws IllegalStateException

— snip — String[] list = new String[ehcaches.size()]; return ehcaches.keySet().toArray(list); //when the Array.length > the keyset: there are null values in the result! We think that the ehcaches content changes between this lines! — snip —

full stacktrace:

at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:768) at net.sf.ehcache.CacheManager.getCache(CacheManager.java:894) at net.sf.ehcache.config.Configuration.getAllActiveCaches(Configuration.java:215) at net.sf.ehcache.config.CacheConfiguration.verifyPoolAllocationsBeforeAddingTo(CacheConfiguration.java:1682) at net.sf.ehcache.config.CacheConfiguration.setupFor(CacheConfiguration.java:1535) at net.sf.ehcache.CacheManager.initializeEhcache(CacheManager.java:1101) at net.sf.ehcache.CacheManager.addCacheNoCheck(CacheManager.java:1156) at net.sf.ehcache.CacheManager.addCache(CacheManager.java:1051)


Fiona OShea 2012-03-01

Any thoughts on this?

Yi Zhang 2012-03-01

Hi Dirk can you please give us a few more details about your use case? i.e. how you’re creating the caches and why you think that the ehcache content would change (e.g. are a lot of clients creating many caches at once?) Any sample code/reproducible case showing the null cache names would be very helpful in figuring out exactly what is happening here.

Dirk Bromberg 2012-03-02


we had one cacheManager.

At runtime we create much caches and remove them. With many threads in a webapp!

  1. creating the manager (singel) manager = net.sf.ehcache.CacheManager.create();

  2. often creating – creating a cache – ehCache = new Cache(new CacheConfiguration(this.cacheName, cacheSize).overflowToDisk(false).eternal(true)); manager.addCache(ehCache);

  3. remove manager.removeCache(cacheName);

  4. everytime Using the cache…

Chris Dennis 2012-03-02

In general I would not recommend accessing a CacheManager from multiple threads without some form of external locking. Although some of the data structures used internally are safe against concurrent access/mutation the class as a whole is not tested in this way, and is not imho intended to be used in this way.

Yi Zhang 2012-03-02

added test case verifying the problem and the fix https://svn.terracotta.org/repo/internal/qa/testng/trunk/Ehcache/EhcacheBigMemoryUsabilityTest/src/test/java/com/terracotta/qa/tc/AddRemoveCacheClusteredPounderTest.java

Fiona OShea 2012-03-02

Is this “fixed” or “as designed”?

Chris Dennis 2012-03-05

It’s fixed - as in this precise NPE should not happen any more. I still stand by my statement however that the CacheManager isn’t really intended for multi-threaded use like this.