Throw an WatcherSettingsException when parsing an invalid hourly schedule.

```
   "schedule" : {
       "hourly" :  [0]
}
```
Was throwing an NPE now it gives a WatcherSettingsException.

Fixes: elastic/elasticsearch#419

Original commit: elastic/x-pack-elasticsearch@f334712f96
This commit is contained in:
Brian Murphy 2015-05-07 13:59:06 -04:00
parent f5c50c44de
commit 2e787fff2b
3 changed files with 8 additions and 5 deletions

View File

@ -10,11 +10,12 @@ package org.elasticsearch.watcher;
*/
public class WatcherSettingsException extends WatcherException {
public WatcherSettingsException(String msg, Throwable cause) {
super(msg, cause);
public WatcherSettingsException(String msg, Object... args) {
super(msg, args);
}
public WatcherSettingsException(String msg) {
super(msg);
public WatcherSettingsException(String msg, Throwable cause, Object... args) {
super(msg, cause, args);
}
}

View File

@ -78,7 +78,7 @@ public class CronSchedule extends CronnableSchedule {
private String expression;
public ValidationException(String expression, Cron.ParseException cause) {
super("invalid cron expression [" + expression + "]. " + cause.getMessage());
super("invalid cron expression [{}]", cause, expression);
this.expression = expression;
}
}

View File

@ -99,6 +99,8 @@ public class HourlySchedule extends CronnableSchedule {
while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
} else if (currentFieldName == null) {
throw new WatcherSettingsException("could not parse [{}] schedule. unexpected token [{}]", TYPE, token);
} else if (MINUTE_FIELD.match(currentFieldName)) {
if (token.isValue()) {
try {