apache/cassandra · error · IllegalArgumentException

Second out of bounds.

Error message

Second out of bounds.

What it means

parseTime validated the seconds component of the time string and found it outside the valid range 0-59. As with hour and minute, CQL `time` requires a real time-of-day value; seconds of 60+ (or negative) raise this IllegalArgumentException. (Leap-second 60 is not accepted.)

Source

Thrown at src/java/org/apache/cassandra/cql3/functions/types/ParseUtils.java:419

        // Parse the time
        int firstColon = str.indexOf(':');
        int secondColon = str.indexOf(':', firstColon + 1);

        // Convert the time; default missing nanos
        if (firstColon > 0 && secondColon > 0 && secondColon < str.length() - 1)
        {
            int period = str.indexOf('.', secondColon + 1);
            hour = Integer.parseInt(str.substring(0, firstColon));
            if (hour < 0 || hour >= 24) throw new IllegalArgumentException("Hour out of bounds.");

            minute = Integer.parseInt(str.substring(firstColon + 1, secondColon));
            if (minute < 0 || minute >= 60) throw new IllegalArgumentException("Minute out of bounds.");

            if (period > 0 && period < str.length() - 1)
            {
                second = Integer.parseInt(str.substring(secondColon + 1, period));
                if (second < 0 || second >= 60) throw new IllegalArgumentException("Second out of bounds.");

                nanos_s = str.substring(period + 1);
                if (nanos_s.length() > 9) throw new IllegalArgumentException(formatError);
                if (!Character.isDigit(nanos_s.charAt(0))) throw new IllegalArgumentException(formatError);
                nanos_s = nanos_s + zeros.substring(0, 9 - nanos_s.length());
                a_nanos = Integer.parseInt(nanos_s);
            }
            else if (period > 0) throw new ParseException(formatError, -1);
            else
            {
                second = Integer.parseInt(str.substring(secondColon + 1));
                if (second < 0 || second >= 60) throw new ParseException("Second out of bounds.", -1);
            }
        }
        else throw new ParseException(formatError, -1);

        long rawTime = 0;
        rawTime += TimeUnit.HOURS.toNanos(hour);

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Convert leap seconds: map :60 to the next second (23:59:60 -> next day 00:00:00) or clamp to :59 before parsing.
  2. Validate seconds between 0 and 59 before calling parseTime.
  3. Use java.time.Instant/Duration handling for leap-second-aware sources instead of the `time` type.
  4. Catch IllegalArgumentException and report the offending component.

Example fix

// before
long nanos = ParseUtils.parseTime("23:59:60"); // throws
// after
String s = "23:59:60";
if (s.endsWith(":60")) s = s.substring(0, 6) + ":59"; // or roll to next day
long nanos = ParseUtils.parseTime(s);
Defensive patterns

Strategy: validation

Validate before calling

int sec = Integer.parseInt(s.substring(s.indexOf(':', s.indexOf(':') + 1) + 1).split("\\.")[0]);
if (sec < 0 || sec > 59) throw new IllegalArgumentException("second must be 0-59: " + sec);

Try / catch

try { return ParseUtils.parseTime(s); }
catch (IllegalArgumentException e) { throw new IllegalArgumentException("Invalid seconds in '" + s + "'", e); }

Prevention

When it happens

Trigger: Calling ParseUtils.parseTime("12:30:60"), "23:59:60" (leap second), or any string whose seconds substring (between the second colon and the period) parses to an int outside [0, 59].

Common situations: Leap-second timestamps from NTP/GPS or astronomical data, rounded cumulative second counts, or data exported from systems that allow 60 for leap seconds.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/ed239977eeb5ff33. Report an issue: GitHub.