Skip to content

Commit d87c7c0

Browse files
committed
Update ScheduleRange validation for negative end
1 parent f68c9bc commit d87c7c0

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

temporal-sdk/src/main/java/io/temporal/client/schedules/ScheduleRange.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ public ScheduleRange(int start) {
2222
* Create a inclusive range for a schedule match value.
2323
*
2424
* @param start The inclusive start of the range
25-
* @param end The inclusive end of the range. Default if unset or less than start is start.
25+
* @param end The inclusive end of the range. Must be non-negative. Default if unset or less than
26+
* start is start.
27+
* @throws IllegalStateException if start or end is negative
2628
*/
2729
public ScheduleRange(int start, int end) {
2830
this(start, end, 0);
@@ -32,11 +34,13 @@ public ScheduleRange(int start, int end) {
3234
* Create a inclusive range for a schedule match value.
3335
*
3436
* @param start The inclusive start of the range
35-
* @param end The inclusive end of the range. Default if unset or less than start is start.
37+
* @param end The inclusive end of the range. Must be non-negative. Default if unset or less than
38+
* start is start.
3639
* @param step The step to take between each value. Default if unset or 0, is 1.
40+
* @throws IllegalStateException if start, end, or step is negative
3741
*/
3842
public ScheduleRange(int start, int end, int step) {
39-
Preconditions.checkState(start >= 0 && step >= 0 && step >= 0);
43+
Preconditions.checkState(start >= 0 && end >= 0 && step >= 0);
4044
this.start = start;
4145
this.end = end;
4246
this.step = step;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.temporal.client.schedules;
2+
3+
import org.junit.Assert;
4+
import org.junit.Test;
5+
6+
public class ScheduleRangeTest {
7+
@Test
8+
public void rejectsNegativeEnd() {
9+
Assert.assertThrows(IllegalStateException.class, () -> new ScheduleRange(0, -1));
10+
Assert.assertThrows(IllegalStateException.class, () -> new ScheduleRange(0, -1, 0));
11+
}
12+
}

0 commit comments

Comments
 (0)