Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Use ROOT Locale for Strings to prevent inconsistencies in format (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
qreshi authored Jun 14, 2019
1 parent 1b3e0f8 commit c0d1706
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.HashSet;
import java.util.Locale;
import java.util.Objects;
import java.util.Set;

Expand Down Expand Up @@ -59,7 +60,9 @@ public class IntervalSchedule implements Schedule {

public IntervalSchedule(Instant startTime, int interval, ChronoUnit unit) {
if (!SUPPORTED_UNITS.contains(unit)) {
throw new IllegalArgumentException(String.format("Interval unit %s is not supported, expects %s", unit, SUPPORTED_UNITS));
throw new IllegalArgumentException(
String.format(Locale.ROOT, "Interval unit %s is not supported, expects %s",
unit, SUPPORTED_UNITS));
}
this.startTime = startTime;
this.interval = interval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.time.Instant;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Locale;

/**
* Schedule XContent parser.
Expand All @@ -43,7 +44,9 @@ public static Schedule parse(XContentParser parser) throws IOException {
switch (cronField) {
case CronSchedule.EXPRESSION_FIELD: expression = parser.text(); break;
case CronSchedule.TIMEZONE_FIELD: timezone = ZoneId.of(parser.text()); break;
default: throw new IllegalArgumentException(String.format("Unknown cron field %s", cronField));
default:
throw new IllegalArgumentException(
String.format(Locale.ROOT, "Unknown cron field %s", cronField));
}
}
XContentParserUtils.ensureExpectedToken(XContentParser.Token.END_OBJECT, parser.currentToken(), parser::getTokenLocation);
Expand All @@ -59,14 +62,18 @@ public static Schedule parse(XContentParser parser) throws IOException {
switch (intervalField) {
case IntervalSchedule.START_TIME_FIELD: startTime = Instant.ofEpochMilli(parser.longValue()); break;
case IntervalSchedule.PERIOD_FIELD: period = parser.intValue(); break;
case IntervalSchedule.UNIT_FIELD: unit = ChronoUnit.valueOf(parser.text().toUpperCase()); break;
default: throw new IllegalArgumentException(String.format("Unknown interval field %s", intervalField));
case IntervalSchedule.UNIT_FIELD: unit = ChronoUnit.valueOf(parser.text().toUpperCase(Locale.ROOT)); break;
default:
throw new IllegalArgumentException(
String.format(Locale.ROOT, "Unknown interval field %s", intervalField));
}
}
XContentParserUtils.ensureExpectedToken(XContentParser.Token.END_OBJECT, parser.currentToken(), parser::getTokenLocation);
parser.nextToken();
return new IntervalSchedule(startTime, period, unit);
default: throw new IllegalArgumentException(String.format("Unknown schedule type %s", fieldName));
default:
throw new IllegalArgumentException(
String.format(Locale.ROOT, "Unknown schedule type %s", fieldName));
}
}
throw new IllegalArgumentException("Invalid schedule document object.");
Expand Down

0 comments on commit c0d1706

Please sign in to comment.