diff --git a/core/src/main/java/hudson/scheduler/CronTab.java b/core/src/main/java/hudson/scheduler/CronTab.java index 9c17bb40e6cf1a778ce47638272972a4c047c10c..81fa5075c90d574f5ae4870aab954df09d918778 100644 --- a/core/src/main/java/hudson/scheduler/CronTab.java +++ b/core/src/main/java/hudson/scheduler/CronTab.java @@ -326,6 +326,9 @@ public final class CronTab { * See {@link #ceil(long)}. * * This method modifies the given calendar and returns the same object. + * + * @throws RareOrImpossibleDateException if the date isn't hit in the 2 years after it indicates an impossible + * (e.g. Jun 31) date, or at least a date too rare to be useful. This addresses JENKINS-41864 and was added in TODO */ public Calendar ceil(Calendar cal) { Calendar twoYearsFuture = (Calendar) cal.clone(); @@ -333,7 +336,7 @@ public final class CronTab { OUTER: while (true) { if (cal.compareTo(twoYearsFuture) > 0) { - // we went at least two years into the future + // we went too far into the future throw new RareOrImpossibleDateException(); } for (CalendarField f : CalendarField.ADJUST_ORDER) { @@ -384,6 +387,9 @@ public final class CronTab { * See {@link #floor(long)} * * This method modifies the given calendar and returns the same object. + * + * @throws RareOrImpossibleDateException if the date isn't hit in the 2 years before it indicates an impossible + * (e.g. Jun 31) date, or at least a date too rare to be useful. This addresses JENKINS-41864 and was added in TODO */ public Calendar floor(Calendar cal) { Calendar twoYearsAgo = (Calendar) cal.clone(); @@ -392,7 +398,7 @@ public final class CronTab { OUTER: while (true) { if (cal.compareTo(twoYearsAgo) < 0) { - // we went at least two years into the past + // we went too far into the past throw new RareOrImpossibleDateException(); } for (CalendarField f : CalendarField.ADJUST_ORDER) { diff --git a/core/src/main/java/hudson/scheduler/RareOrImpossibleDateException.java b/core/src/main/java/hudson/scheduler/RareOrImpossibleDateException.java index c45d18f808f7875d81e75be76998521f388c91b8..7bd9d2562fdfcf9b1206c4ee9bfb170a451535bd 100644 --- a/core/src/main/java/hudson/scheduler/RareOrImpossibleDateException.java +++ b/core/src/main/java/hudson/scheduler/RareOrImpossibleDateException.java @@ -26,6 +26,28 @@ package hudson.scheduler; import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; +import java.util.Calendar; + +/** + * This exception is thrown when trying to determine the previous or next occurrence of a given date determines + * that it's not happened, or going to happen, within some time period (e.g. within the next year). + * + *

This can typically have a few different reasons:

+ * + * + * + * @see CronTab#floor(Calendar) + * @see CronTab#ceil(Calendar) + * @since TODO + */ @Restricted(NoExternalUse.class) public class RareOrImpossibleDateException extends RuntimeException { } diff --git a/core/src/main/resources/hudson/triggers/Messages.properties b/core/src/main/resources/hudson/triggers/Messages.properties index c82efebf15d58a2c89d8fce9e46a96539875cbde..245b3c4de4bc870b9bf4aee3d2b6aa063eee89fb 100644 --- a/core/src/main/resources/hudson/triggers/Messages.properties +++ b/core/src/main/resources/hudson/triggers/Messages.properties @@ -29,7 +29,7 @@ TimerTrigger.MissingWhitespace=You appear to be missing whitespace between * and TimerTrigger.no_schedules_so_will_never_run=No schedules so will never run TimerTrigger.TimerTriggerCause.ShortDescription=Started by timer TimerTrigger.would_last_have_run_at_would_next_run_at=Would last have run at {0}; would next run at {1}. -TimerTrigger.the_specified_cron_tab_is_rare_or_impossible=This cron tab will match dates only rarely (e.g. February 29) or \ +TimerTrigger.the_specified_cron_tab_is_rare_or_impossible=This schedule will match dates only rarely (e.g. February 29) or \ never (e.g. June 31), so this job may be triggered very rarely, if at all. Trigger.init=Initializing timer for triggers SCMTrigger.AdministrativeMonitorImpl.DisplayName=Too Many SCM Polling Threads