scwang90/SmartRefreshLayout · error · RuntimeException

error in parsing "${s}"

Error message

error in parsing "${s}"

What it means

Thrown by PathParser's number-extraction loop when Float.parseFloat fails on a token extracted from the path-data string. The extract() helper splits the string on commas/spaces/'-'/'.' boundaries; if the resulting token is not a valid float (stray letters, misplaced signs, double dots like '1..2'), a NumberFormatException is caught here and rethrown as this RuntimeException with the full string in the message.

Source

Thrown at refresh-drawable-path/src/main/java/com/scwang/smart/drawable/path/PathParser.java:346

            while (startPosition < totalLength) {
                extract(s, startPosition, result);
                endPosition = result.mEndPosition;

                if (startPosition < endPosition) {
                    results[count++] = Float.parseFloat(
                            s.substring(startPosition, endPosition));
                }

                if (result.mEndWithNegOrDot) {
                    // Keep the '-' or '.' sign with next number.
                    startPosition = endPosition;
                } else {
                    startPosition = endPosition + 1;
                }
            }
            return copyOfRange(results, 0, count);
        } catch (NumberFormatException e) {
            throw new RuntimeException("error in parsing \"" + s + "\"", e);
        }
    }

    /**
     * Calculate the position of the next comma or space or negative sign
     *
     * @param s      the string to search
     * @param start  the position to start searching
     * @param result the result of the extraction, including the position of the
     *               the starting position of next number, whether it is ending with a '-'.
     */
    private static void extract(String s, int start, ExtractFloatResult result) {
        // Now looking for ' ', ',', '.' or '-' from the start.
        int currentIndex = start;
        boolean foundSeparator = false;
        result.mEndWithNegOrDot = false;
        boolean secondDot = false;
        boolean isExponential = false;

View on GitHub (pinned to 224db48f8a)

Solutions

  1. Inspect the string in the exception message — the quoted 's' shows exactly which input failed tokenization.
  2. Fix malformed numbers: remove stray characters, collapse double dots/signs, and ensure exactly one '-' or '.' per number.
  3. Generate the string with String.format(Locale.US, "%.2f", value) so ',' never appears as a decimal separator.
  4. Sanitize/validate the path string against ^[MmLlHhVvCcSsQqTtAaZz0-9,\s.+-]+$ plus a float-parse pass before handing it to the parser.
  5. Keep parser calls in a try-catch with a safe fallback path so bad input degrades gracefully instead of crashing.

Example fix

// before
String d = "M" + x + "," + y + " L" + x2; // y='-5' -> token '..' or '--5' possible
PathParser.createNodesFromPathData(d);

// after
String d = String.format(Locale.US, "M%f,%f L%f,%f", x, y, x2, y2);
PathDataNode[] nodes;
try {
    nodes = PathParser.createNodesFromPathData(d);
} catch (RuntimeException e) {
    nodes = PathParser.createNodesFromPathData("M0,0"); // fallback
}
Defensive patterns

Strategy: validation

Validate before calling

// Verify every token the parser will extract is a valid float
boolean tokensAreFloats(String d) {
    for (String tok : d.split("[MmLlHhVvCcSsQqTtAaZz,\\s]+")) {
        if (tok.isEmpty()) continue;
        if (!tok.matches("[+-]?(\\d+\\.?\\d*|\\.\\d+)")) return false;
    }
    return true;
}

Try / catch

try {
    nodes = PathParser.createNodesFromPathData(pathData);
} catch (RuntimeException e) {
    // message quotes the offending string; log it and use a safe default
    nodes = new PathDataNode[0];
}

Prevention

When it happens

Trigger: Passing a path string containing tokens that are not valid floats: letters inside numbers ('M10x20'), double dots ('1..2'), consecutive signs ('--5'), scientific notation ('1e5'), or a 'd' string that got corrupted/truncated during string concatenation. It is the lower-level sibling of error 0 — this one fires during createNodesFromPathData/getFloats tokenization, before any Path is built.

Common situations: Dynamically composing the 'd' attribute with string concatenation and dropping a separator; embedding a path in XML/JSON where escapes mangle '-' characters; locale-formatted numbers with ',' as the decimal separator being re-split incorrectly; copying path data from an optimizer that emits notation this parser does not accept.

Related errors


AI-assisted analysis of scwang90/SmartRefreshLayout@224db48f8a (2026-08-14). Data as JSON: /api/errors/3f9156832795efef. Report an issue: GitHub.