MyCATApache/Mycat-Server · error · IllegalArgumentException
Interval string does not match second-nano format of…
Error message
Interval string does not match second-nano format of ss.nnnnnnnnn
What it means
parseSecondNano parses a seconds-with-fraction string like '12.999999999' and throws this IllegalArgumentException when the input does not split into exactly two parts around the decimal point with non-empty valid components — i.e. it is not in ss.nnnnnnnnn form.
Solutions
- Ensure the string has exactly one '.' separating integer seconds and nanoseconds, e.g. '12.5' not '12' or '12.5.6'
- Convert locale decimal commas to '.' before parsing
- Validate with a regex like ^\d*\.\d*$ before calling
Example fix
// before
long micros = interval.parseSecondNano("12,5");
// after
long micros = interval.parseSecondNano("12.500000000"); Defensive patterns
Strategy: validation
Validate before calling
private static final Pattern SS_N = Pattern.compile("^\\d*\\.\\d{1,9}$");
static void requireSecondNano(String s) {
if (s == null || !SS_N.matcher(s).matches())
throw new IllegalArgumentException("expected ss.nnnnnnnnn, got: " + s);
} Type guard
static boolean isSecondNano(String s) {
return s != null && s.matches("\\d*\\.\\d{1,9}");
} Try / catch
try {
long micros = parseSecondNano(s);
} catch (IllegalArgumentException e) {
log.warn("Malformed seconds.nanos '{}'", s);
micros = 0L;
} Prevention
- Ensure exactly one '.' with digits on both sides
- Replace locale decimal commas with '.' first
- Pad the fractional part when fixed width is required
When it happens
Trigger: Calling CalendarInterval.parseSecondNano("12"), parseSecondNano("1.2.3"), parseSecondNano("abc.def"), or parseSecondNano("") — e.g. from the micros() accessor with a malformed seconds string.
Common situations: Truncated fractional seconds from string splitting, locale decimal commas ('12,5'), missing nano part after the dot.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Interval string does not match year-month format of 'y-m':
- Interval string does not match day-time format of 'd…
- outside range [ , ]
- Interval year-month string was null
- Error parsing interval year-month string:
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/4abb246875acc232.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/memory/unsafe/types/CalendarInterval.java:247
}
/**
* Parse second_nano string in ss.nnnnnnnnn format to microseconds
*/
public static long parseSecondNano(String secondNano) throws IllegalArgumentException {
String[] parts = secondNano.split("\\.");
if (parts.length == 1) {
return toLongWithRange("second", parts[0], Long.MIN_VALUE / MICROS_PER_SECOND,
Long.MAX_VALUE / MICROS_PER_SECOND) * MICROS_PER_SECOND;
} else if (parts.length == 2) {
long seconds = parts[0].equals("") ? 0L : toLongWithRange("second", parts[0],
Long.MIN_VALUE / MICROS_PER_SECOND, Long.MAX_VALUE / MICROS_PER_SECOND);
long nanos = toLongWithRange("nanosecond", parts[1], 0L, 999999999L);
return seconds * MICROS_PER_SECOND + nanos / 1000L;
} else {
throw new IllegalArgumentException(
"Interval string does not match second-nano format of ss.nnnnnnnnn");
}
}
public final int months;
public final long microseconds;
public CalendarInterval(int months, long microseconds) {
this.months = months;
this.microseconds = microseconds;
}
public CalendarInterval add(CalendarInterval that) {
int months = this.months + that.months;
long microseconds = this.microseconds + that.microseconds;
return new CalendarInterval(months, microseconds);
}
View on GitHub (pinned to 65f8d8beb7)