spring-projects/spring-boot · error · IllegalArgumentException
Can't parse ' ' to instant
Error message
Can't parse '%s' to instant
What it means
IllegalArgumentException thrown by MavenBuildOutputTimestamp when the non-numeric, non-empty, ≥2-char outputTimestamp cannot be parsed as an OffsetDateTime (DateTimeParseException). The plugin only accepts two formats: pure epoch seconds (numeric) or a valid ISO-8601 offset date-time; anything else lands here.
Solutions
- Use the ISO-8601 offset form: <outputTimestamp>2024-01-01T00:00:00Z</outputTimestamp>.
- Or use epoch seconds: <outputTimestamp>1700000000</outputTimestamp> (numeric branch, no parse).
- Omit the property to disable reproducible-timestamp injection.
- Validate the value with `OffsetDateTime.parse(...)` in a quick test.
Example fix
// before: <project.build.outputTimestamp>2024/01/01 12:00</project.build.outputTimestamp> // after: <project.build.outputTimestamp>2024-01-01T12:00:00Z</project.build.outputTimestamp>
Defensive patterns
Strategy: validation
Validate before calling
// Validate format before invoking:
String ts = outputTimestamp;
boolean ok = (ts == null || ts.isEmpty())
|| (ts.chars().allMatch(Character::isDigit))
|| canParseOffsetDateTime(ts);
// where:
boolean canParseOffsetDateTime(String s) { try { OffsetDateTime.parse(s); return true; } catch (DateTimeParseException e) { return false; } } Try / catch
try {
// invoke goal that calls toFileTime
} catch (IllegalArgumentException ex) {
if (ex.getMessage().startsWith("Can't parse") && ex.getMessage().endsWith("to instant")) {
// convert to ISO-8601 offset or epoch seconds, then retry
}
throw ex;
} Prevention
- Always use ISO-8601 with explicit offset (e.g. 2024-01-01T00:00:00Z).
- Avoid locale-specific date formats in build properties.
- Add a CI lint that parses the configured outputTimestamp.
When it happens
Trigger: Setting <project.build.outputTimestamp> to a non-numeric, non-ISO-8601 string (e.g., '2024/01/01', 'Jan 1 2024', or a date without time/offset that OffsetDateTime.parse rejects).
Common situations: Using a locale-specific date format; passing a LocalDate-only string; missing the offset/zone portion; copy-pasting a timestamp from a non-Java source.
Related errors
- Invalid value for parameter 'outputTimestamp'
- ' ' is not within the valid range to
- A jar or war file is required for building image
- Could not build classpath
- Error packaging archive for image
AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11).
Data as JSON: /api/errors/c7a770d1da99d778.
Report an issue: GitHub.
Appendix: 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 270dfe353f)