Commits

jhouse  committed f1ebc4e

QUARTZ-678: CronTrigger may return a firing time not included in the calender

git-svn-id: http://svn.opensymphony.com/svn/quartz/trunk@81669f7d36a-ea1c-0410-88ea-9fd03e4c9665

  • Participants
  • Parent commits b4007be

Comments (0)

Files changed (1)

File src/java/org/quartz/CronTrigger.java

      */
     public static final int MISFIRE_INSTRUCTION_DO_NOTHING = 2;
 
+    private static final int YEAR_TO_GIVEUP_SCHEDULING_AT = 2299;
+    
+    
     /*
      * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      * 
     {
         nextFireTime = getFireTimeAfter(previousFireTime);
         
+        if (nextFireTime == null || calendar == null) {
+        	return;
+        }
+        
         Date now = new Date();
-        do {
-            while (nextFireTime != null && calendar != null
-                    && !calendar.isTimeIncluded(nextFireTime.getTime())) {
-                nextFireTime = getFireTimeAfter(nextFireTime);
+        while (nextFireTime != null && !calendar.isTimeIncluded(nextFireTime.getTime())) {
+
+            nextFireTime = getFireTimeAfter(nextFireTime);
+
+            if(nextFireTime == null)
+            	break;
+            
+            //avoid infinite loop
+            java.util.Calendar c = java.util.Calendar.getInstance();
+            c.setTime(nextFireTime);
+            if (c.get(java.util.Calendar.YEAR) > YEAR_TO_GIVEUP_SCHEDULING_AT) {
+                nextFireTime = null;
             }
             
             if(nextFireTime != null && nextFireTime.before(now)) {
                     continue;
                 }
             }
-        }while(false);
+        }
     }
 
     /**