• Bug
  • Status: Closed
  • 1 Critical
  • Resolution: Fixed
  • ehcache-core
  • hsingh
  • Reporter: amiller
  • October 16, 2009
  • 0
  • Watchers: 0
  • January 17, 2013
  • October 16, 2009

Description

The following code:

mport net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; import net.sf.ehcache.Element;

public class ehcacheTest {

public static void main(String[] s) {

   long maxLiveTime = Long.MAX_VALUE;

   final Cache cache = new Cache("bla", 5000, false, false, maxLiveTime, 30);
   final CacheManager cacheManager = CacheManager.create();

   cacheManager.addCache(cache);

   Element e = new Element("key", "bla");
   cache.put(e);

   Element e2 = cache.get("key");
   System.out.println(e2);

}

}

throws this error:

java.lang.IllegalArgumentException: timeToLive can’t be negative at net.sf.ehcache.Element.setTimeToLive(Element.java:313) at net.sf.ehcache.Cache.applyDefaultsToElementWithoutLifespanSet(Cache.java:903) at net.sf.ehcache.Cache.put(Cache.java:867) at net.sf.ehcache.Cache.put(Cache.java:807) at net.sf.ehcache.CacheTest.testMaxLongTTLIsEternal(CacheTest.java:2689)

due to a down-cast from long to int in Cache.applyDefaultToElementWithoutLifespanSet().

Comments

Alex Miller 2009-10-16

Added tests for Long.MAX_VALUE and Integer.MAX_VALUE, fixed downcast to use Integer.MAX_VALUE if > than that.

Himadri Singh 2009-11-19

Verified in

product-name = Ehcache Core version = 1.7.1-SNAPSHOT built-by = cruise build-jdk = 1.6.0_16 build-time = 2009-11-17 03:01:12 build-revision = 1436