apache/pulsar · error · IllegalArgumentException
Invalid time unit '${lastChar}'
Error message
Invalid time unit '${lastChar}' What it means
Unit-switch default in RelativeTimeUtil.parseRelativeTimeInSeconds: the parsed duration's last character is not one of s/m/h/d/w/y, so the switch falls to the default branch and rejects the string; the trailing unit character of the relativeTime argument is the faulty input.
Source
Thrown at pulsar-cli-utils/src/main/java/org/apache/pulsar/cli/converters/RelativeTimeUtil.java:62
long duration = Long.parseLong(relativeTime.substring(0, lastIndex));
switch (timeUnit) {
case 's':
return duration;
case 'm':
return TimeUnit.MINUTES.toSeconds(duration);
case 'h':
return TimeUnit.HOURS.toSeconds(duration);
case 'd':
return TimeUnit.DAYS.toSeconds(duration);
case 'w':
return 7 * TimeUnit.DAYS.toSeconds(duration);
// No unit for months
case 'y':
return 365 * TimeUnit.DAYS.toSeconds(duration);
default:
throw new IllegalArgumentException("Invalid time unit '" + lastChar + "'");
}
}
/**
* Convert nanoseconds to seconds and keep three decimal places.
* @param ns
* @return seconds
*/
public static double nsToSeconds(long ns) {
double seconds = (double) ns / 1_000_000_000;
BigDecimal bd = new BigDecimal(seconds);
return bd.setScale(3, RoundingMode.HALF_UP).doubleValue();
}
}
View on GitHub (pinned to 820761864e)
Solutions
- Use a supported unit suffix: s, m, h, d, w, or y (no months)
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pulsar-cli-utils/src/main/java/org/apache/pulsar/cli/converters/RelativeTimeUtil.java:62 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/fcfbd2c155f73cfe.
Report an issue: GitHub.