spring-projects/spring-boot · error · IllegalArgumentException
Can't parse '%s' to instant
Error message
Can't parse '%s' to instant
What it means
Thrown by MavenBuildOutputTimestamp.toInstant as an IllegalArgumentException catching a DateTimeParseException when the outputTimestamp is non-numeric (so it is treated as an ISO-8601 OffsetDateTime) but cannot be parsed. The parser expects ISO_OFFSET_DATE_TIME (e.g. 2024-01-01T00:00:00Z); any other format, a typo, or a stray token triggers this. The %s interpolates the offending input verbatim.
Source
Thrown at build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/MavenBuildOutputTimestamp.java:98
if (!StringUtils.hasLength(this.timestamp)) {
return null;
}
if (isNumeric(this.timestamp)) {
return Instant.ofEpochSecond(Long.parseLong(this.timestamp));
}
if (this.timestamp.length() < 2) {
return null;
}
try {
Instant instant = OffsetDateTime.parse(this.timestamp).withOffsetSameInstant(ZoneOffset.UTC).toInstant();
if (instant.isBefore(DATE_MIN) || instant.isAfter(DATE_MAX)) {
throw new IllegalArgumentException(
String.format("'%s' is not within the valid range %s to %s", instant, DATE_MIN, DATE_MAX));
}
return instant;
}
catch (DateTimeParseException pe) {
throw new IllegalArgumentException(String.format("Can't parse '%s' to instant", this.timestamp));
}
}
private static boolean isNumeric(String str) {
for (char c : str.toCharArray()) {
if (!Character.isDigit(c)) {
return false;
}
}
return true;
}
}
View on GitHub (pinned to 5b2dbdbb8b)
Solutions
- Use a strict ISO-8601 offset date-time: yyyy-MM-dd'T'HH:mm:ssXXX (e.g. 2024-01-01T00:00:00Z).
- If you have epoch seconds, pass them as a plain integer string (digits only).
- Avoid ${maven.build.timestamp} unless you have reformatted it to ISO-8601.
- Set <maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ssXXX</maven.build.timestamp.format> if you must interpolate.
Example fix
// before <project.build.outputTimestamp>2024-01-01</project.build.outputTimestamp> // after — full ISO-8601 offset date-time <project.build.outputTimestamp>2024-01-01T00:00:00Z</project.build.outputTimestamp>
Defensive patterns
Strategy: validation
Validate before calling
// Reject non-ISO, non-numeric timestamps early
import java.time.OffsetDateTime, java.time.format.DateTimeParseException;
void checkFormat(String ts) {
if (ts == null || ts.isBlank()) return;
if (ts.chars().allMatch(Character::isDigit)) return; // numeric epoch seconds
try { OffsetDateTime.parse(ts); }
catch (DateTimeParseException e) {
throw new IllegalArgumentException("outputTimestamp must be ISO-8601 or integer seconds: " + ts);
}
} Prevention
- Use ISO-8601 offset date-time (yyyy-MM-dd'T'HH:mm:ssXXX) or pure integer epoch seconds.
- Avoid interpolating ${maven.build.timestamp} unless reformatted to ISO-8601.
- Document the accepted formats in the project to prevent contributors from using locale dates.
When it happens
Trigger: Setting outputTimestamp to '2024-01-01' (date only, no time/offset); '2024/01/01 12:00:00' (wrong separators); a Git ISO-short format; a value like 'now' or '${maven.build.timestamp}'; a localized date string; an integer-like value that is not purely digits and not ISO.
Common situations: Using ${maven.build.timestamp} which is formatted by Maven's timestamp format (not ISO-8601 by default); passing a date from another tool with a different format; copy-pasting a date in a locale-specific format; using an ISO-local date without the time component.
Related errors
- '{}' is not within the valid range {} to {}
- Invalid value for parameter 'outputTimestamp'
- Failed to load layers configuration with name '%s': '%s' not
- Failed to process custom layers configuration {}
- Could not build classpath
AI-assisted analysis of spring-projects/spring-boot@5b2dbdbb8b (2026-08-04).
Data as JSON: /data/errors/c7a770d1da99d778.json.
Report an issue: GitHub.