diff --git a/temporal-sdk/src/main/java/io/temporal/client/schedules/ScheduleRange.java b/temporal-sdk/src/main/java/io/temporal/client/schedules/ScheduleRange.java index 4d79d50d4e..29bd596c56 100644 --- a/temporal-sdk/src/main/java/io/temporal/client/schedules/ScheduleRange.java +++ b/temporal-sdk/src/main/java/io/temporal/client/schedules/ScheduleRange.java @@ -22,7 +22,9 @@ public ScheduleRange(int start) { * Create a inclusive range for a schedule match value. * * @param start The inclusive start of the range - * @param end The inclusive end of the range. Default if unset or less than start is start. + * @param end The inclusive end of the range. Must be non-negative. Default if unset or less than + * start is start. + * @throws IllegalStateException if start or end is negative */ public ScheduleRange(int start, int end) { this(start, end, 0); @@ -32,11 +34,13 @@ public ScheduleRange(int start, int end) { * Create a inclusive range for a schedule match value. * * @param start The inclusive start of the range - * @param end The inclusive end of the range. Default if unset or less than start is start. + * @param end The inclusive end of the range. Must be non-negative. Default if unset or less than + * start is start. * @param step The step to take between each value. Default if unset or 0, is 1. + * @throws IllegalStateException if start, end, or step is negative */ public ScheduleRange(int start, int end, int step) { - Preconditions.checkState(start >= 0 && step >= 0 && step >= 0); + Preconditions.checkState(start >= 0 && end >= 0 && step >= 0); this.start = start; this.end = end; this.step = step; diff --git a/temporal-sdk/src/test/java/io/temporal/client/schedules/ScheduleRangeTest.java b/temporal-sdk/src/test/java/io/temporal/client/schedules/ScheduleRangeTest.java new file mode 100644 index 0000000000..f179dac18d --- /dev/null +++ b/temporal-sdk/src/test/java/io/temporal/client/schedules/ScheduleRangeTest.java @@ -0,0 +1,12 @@ +package io.temporal.client.schedules; + +import org.junit.Assert; +import org.junit.Test; + +public class ScheduleRangeTest { + @Test + public void rejectsNegativeEnd() { + Assert.assertThrows(IllegalStateException.class, () -> new ScheduleRange(0, -1)); + Assert.assertThrows(IllegalStateException.class, () -> new ScheduleRange(0, -1, 0)); + } +}