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:
+ * + *