Uploaded image for project: 'Railo'
  1. Railo
  2. RAILO-2543

CachePut with EHCache throws java.lang.IllegalArgumentException for timeSpans longer than 24.8 days

    Details

    • Steps to Reproduce:
      Hide

      Setup an EHCache as a default Object cache connection and run the following code:

      <cfscript>
      CachePut("test", 1, 24.9);
      </cfscript>
      

      or

      <cfscript>
      CachePut("test", 1, CreateTimeSpan(25,0,0,0));
      </cfscript>
      
      Show
      Setup an EHCache as a default Object cache connection and run the following code: <cfscript> CachePut( "test" , 1, 24.9); </cfscript> or <cfscript> CachePut( "test" , 1, CreateTimeSpan(25,0,0,0)); </cfscript>

      Description

      When passing to CachePut a timeSpan or idleTime argument with a value longer than ~24.8 days EHCache throws a java.lang.IllegalArgumentException with a message "timeToLive can't be negative".

      This is an EHCache specific issue and is caused by a casting error in https://github.com/getrailo/railo/blob/master/railo-java/railo-core/src/railo/runtime/cache/eh/EHCacheSupport.java

      timeSpans are first cast to int and then converted to seconds, resulting in massive loss of precision and integer overflow errors.
      lines 71 & 72 are:

      Integer idle = idleTime==null?null:new Integer((int)idleTime.longValue()/1000);
      Integer live = liveTime==null?null:new Integer((int)liveTime.longValue()/1000);
      

      timeSpans should be first converted to seconds and then cast to Integer
      lines 71 & 72 should be:

      Integer idle = idleTime==null?null:new Integer((int)(idleTime.longValue()/1000));
      Integer live = liveTime==null?null:new Integer((int)(liveTime.longValue()/1000));
      

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                igal-getrailo.org Igal .
                Reporter:
                apostolos Apostolos Tsakpinis
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: