apache/cassandra · error · NumberFormatException

Unexpected characters between pos

Error message

Unexpected characters between pos 

What it means

parseHumanReadable throws this NumberFormatException when, after parsing the number (and optional binary exponent and SI prefix), there are leftover unrecognized characters before the end of the string (only allowed when no unit was expected). It means the value has trailing garbage the parser cannot interpret.

Solutions

  1. Remove the unrecognized trailing characters from the value
  2. Use a supported SI/binary prefix (k, M, G, Ki, Mi, Gi...) or none at all
  3. Log the offending config key with its value when wrapping this exception
  4. Trim whitespace and comments from the configured string before parsing

Example fix

// before: column_index_size = "64KBKB"
// after:  column_index_size = "64KB"
Defensive patterns

Strategy: validation

Validate before calling

if (value != null && value.matches(".*[^0-9.kKmMgGtTpPbB]\\s*$")) log.warn("suspect trailing characters in value: {}", value);

Try / catch

try { return FBUtilities.parseHumanReadable(s, sep, unit); } catch (NumberFormatException e) { throw new ConfigurationException("Unparsable trailing characters in '" + s + "'", e); }

Prevention

When it happens

Trigger: Calling parseHumanReadable with a datum containing unknown trailing characters after number/unit, e.g. "10GBx", "5MB!!", or "10 KiB each" when a unit is expected.

Common situations: Hand-edited config lines with stray comments or units appended twice (e.g. '512KBKB'), copy-paste artifacts, or non-SI suffixes not supported by the parser.

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


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

Appendix: source

Thrown at src/java/org/apache/cassandra/utils/FBUtilities.java:1173

            int prefixIndex = UNIT_PREFIXES.indexOf(prefixChar);
            if (prefixIndex >= 0)
            {
                prefixIndex -= UNIT_PREFIXES_BASE;
                ++pos;
                if (pos < end && datum.charAt(pos) == 'i')
                {
                    ++pos;
                    v = Math.scalb(v, prefixIndex * 10);
                }
                else
                {
                    v *= Math.exp(Math.log(1000.0) * prefixIndex);
                }
            }
        }

        if (pos != end && unit != null)
            throw new NumberFormatException("Unexpected characters between pos " + pos + " and " + end + " in " + datum);

        return v;
    }

    public static long parseHumanReadableBytes(String value)
    {
        return (long) parseHumanReadable(value, null, "B");
    }

    /**
     * Parse a double where both a direct value and a percentage are accepted.
     * For example, for inputs "0.1" and "10%", this function will return 0.1.
     */
    public static double parsePercent(String value)
    {
        value = value.trim();
        if (value.endsWith("%"))
        {

View on GitHub (pinned to 88fd0f6a0e)