CronSequenceGenerator prevents stack overflow in case of inverted range
Issue: SPR-14462
(cherry picked from commit e431624)
			
			
This commit is contained in:
		
							parent
							
								
									0065a160cc
								
							
						
					
					
						commit
						da59b4da9b
					
				| 
						 | 
					@ -95,6 +95,7 @@ public class CronSequenceGenerator {
 | 
				
			||||||
		parse(expression);
 | 
							parse(expression);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * Return the cron pattern that this sequence generator has been built for.
 | 
						 * Return the cron pattern that this sequence generator has been built for.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
| 
						 | 
					@ -378,6 +379,10 @@ public class CronSequenceGenerator {
 | 
				
			||||||
			throw new IllegalArgumentException("Range less than minimum (" + min + "): '" +
 | 
								throw new IllegalArgumentException("Range less than minimum (" + min + "): '" +
 | 
				
			||||||
					field + "' in expression \"" + this.expression + "\"");
 | 
										field + "' in expression \"" + this.expression + "\"");
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
							if (result[0] > result[1]) {
 | 
				
			||||||
 | 
								throw new IllegalArgumentException("Invalid inverted range: '" + field +
 | 
				
			||||||
 | 
										"' in expression \"" + this.expression + "\"");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		return result;
 | 
							return result;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -388,6 +393,7 @@ public class CronSequenceGenerator {
 | 
				
			||||||
	 * fields separated by single spaces.
 | 
						 * fields separated by single spaces.
 | 
				
			||||||
	 * @param expression the expression to evaluate
 | 
						 * @param expression the expression to evaluate
 | 
				
			||||||
	 * @return {@code true} if the given expression is a valid cron expression
 | 
						 * @return {@code true} if the given expression is a valid cron expression
 | 
				
			||||||
 | 
						 * @since 4.3
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public static boolean isValidExpression(String expression) {
 | 
						public static boolean isValidExpression(String expression) {
 | 
				
			||||||
		String[] fields = StringUtils.tokenizeToStringArray(expression, " ");
 | 
							String[] fields = StringUtils.tokenizeToStringArray(expression, " ");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -56,6 +56,26 @@ public class CronSequenceGeneratorTests {
 | 
				
			||||||
		new CronSequenceGenerator("*/-1 * * * * *").next(new Date(2012, 6, 1, 9, 0));
 | 
							new CronSequenceGenerator("*/-1 * * * * *").next(new Date(2012, 6, 1, 9, 0));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Test(expected = IllegalArgumentException.class)
 | 
				
			||||||
 | 
						public void withInvertedMinuteRange() {
 | 
				
			||||||
 | 
							new CronSequenceGenerator("* 6-5 * * * *").next(new Date(2012, 6, 1, 9, 0));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Test(expected = IllegalArgumentException.class)
 | 
				
			||||||
 | 
						public void withInvertedHourRange() {
 | 
				
			||||||
 | 
							new CronSequenceGenerator("* * 6-5 * * *").next(new Date(2012, 6, 1, 9, 0));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Test
 | 
				
			||||||
 | 
						public void withSameMinuteRange() {
 | 
				
			||||||
 | 
							new CronSequenceGenerator("* 6-6 * * * *").next(new Date(2012, 6, 1, 9, 0));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Test
 | 
				
			||||||
 | 
						public void withSameHourRange() {
 | 
				
			||||||
 | 
							new CronSequenceGenerator("* * 6-6 * * *").next(new Date(2012, 6, 1, 9, 0));
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	public void validExpression() {
 | 
						public void validExpression() {
 | 
				
			||||||
		assertTrue(CronSequenceGenerator.isValidExpression("0 */2 1-4 * * *"));
 | 
							assertTrue(CronSequenceGenerator.isValidExpression("0 */2 1-4 * * *"));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue