alibaba/spring-cloud-alibaba · error · ParseException
Unexpected character: {}
Error message
Unexpected character: {} What it means
Thrown when a field token's first character is none of '?', '*', '/', 'L', or a digit (guard at CronExpression.java:503-504, the final else of storeExpressionVals). The parser cannot begin a field with an operator like '-', 'W', '#', or an unrecognized letter. It is a checked ParseException from the constructor.
Source
Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/util/CronExpression.java:504
else if (c >= '0' && c <= '9') {
int val = Integer.parseInt(String.valueOf(c));
i++;
if (i >= s.length()) {
addToSet(val, -1, -1, type);
}
else {
c = s.charAt(i);
if (c >= '0' && c <= '9') {
final ValueSet vs = getValue(val, s, i);
val = vs.value;
i = vs.pos;
}
i = checkNext(i, s, val, type);
return i;
}
}
else {
throw new ParseException("Unexpected character: " + c, i);
}
return i;
}
protected int checkNext(final int pos, final String s, final int val, final int type)
throws ParseException {
int end = -1;
int i = pos;
if (i >= s.length()) {
addToSet(val, end, -1, type);
return i;
}
char c = s.charAt(pos);
View on GitHub (pinned to 115d590110)
Solutions
- Move the operator after a numeric value, e.g. '#1' -> '5#1', 'W' -> '15W'.
- Remove stray characters; a field must start with '?', '*', '/', 'L', or a digit.
- Check the cron string encoding (ASCII) and field separators (single spaces).
Example fix
// before
new CronExpression("0 0 0 # * ?");
// after
new CronExpression("0 0 0 ? * 6#3"); // 3rd Friday of the month Defensive patterns
Strategy: validation
Validate before calling
// Every field token must start with '?', '*', '/', 'L', or a digit.
private static final Pattern FIELD_START = Pattern.compile("^[?*/L0-9]");
static boolean allFieldStartsValid(String cron) {
if (cron == null || cron.trim().isEmpty()) return false;
for (String f : cron.trim().split("\\s+")) {
if (!FIELD_START.matcher(f).find()) return false;
}
return true;
} Try / catch
try {
CronExpression cron = new CronExpression(raw);
} catch (ParseException e) {
throw new IllegalArgumentException("Invalid cron expression: " + raw, e);
} Prevention
- Operators (W, #, -) must follow a value, not start a field.
- Keep cron config ASCII and single-space separated.
- Reject stray punctuation at config-load time.
When it happens
Trigger: `new CronExpression("0 0 0 # * ?")` (day-of-month starts with '#'), or `0 0 0 - * ?`, or `0 0 0 W * ?`, or any non-recognized leading char such as `0 0 0 X * ?`.
Common situations: Operators ('W', '#', 'L') placed at the start of a field instead of after a value (e.g. 'W15' written as 'W' alone), stray punctuation, or non-ASCII/letter typos. Also locale/encoding artifacts in config files.
Related errors
- '/' must be followed by an integer.
- Unexpected end of string.
- Increment > 60 : {}
- Increment > 24 : {}
- Increment > 31 : {}
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/e346d3655f033c5b.
Report an issue: GitHub.