{"record":{"id":"3f9156832795efef","repo":"scwang90/SmartRefreshLayout","slug":"error-in-parsing-s","errorCode":null,"errorMessage":"error in parsing \"${s}\"","messagePattern":"error in parsing \"(.+?)\"","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"refresh-drawable-path/src/main/java/com/scwang/smart/drawable/path/PathParser.java","lineNumber":346,"sourceCode":"            while (startPosition < totalLength) {\n                extract(s, startPosition, result);\n                endPosition = result.mEndPosition;\n\n                if (startPosition < endPosition) {\n                    results[count++] = Float.parseFloat(\n                            s.substring(startPosition, endPosition));\n                }\n\n                if (result.mEndWithNegOrDot) {\n                    // Keep the '-' or '.' sign with next number.\n                    startPosition = endPosition;\n                } else {\n                    startPosition = endPosition + 1;\n                }\n            }\n            return copyOfRange(results, 0, count);\n        } catch (NumberFormatException e) {\n            throw new RuntimeException(\"error in parsing \\\"\" + s + \"\\\"\", e);\n        }\n    }\n\n    /**\n     * Calculate the position of the next comma or space or negative sign\n     *\n     * @param s      the string to search\n     * @param start  the position to start searching\n     * @param result the result of the extraction, including the position of the\n     *               the starting position of next number, whether it is ending with a '-'.\n     */\n    private static void extract(String s, int start, ExtractFloatResult result) {\n        // Now looking for ' ', ',', '.' or '-' from the start.\n        int currentIndex = start;\n        boolean foundSeparator = false;\n        result.mEndWithNegOrDot = false;\n        boolean secondDot = false;\n        boolean isExponential = false;","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/scwang90/SmartRefreshLayout/blob/224db48f8af897a930b810a6b6fc55af8cef0d57/refresh-drawable-path/src/main/java/com/scwang/smart/drawable/path/PathParser.java#L328-L364","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect the string in the exception message — the quoted 's' shows exactly which input failed tokenization.","Fix malformed numbers: remove stray characters, collapse double dots/signs, and ensure exactly one '-' or '.' per number.","Generate the string with String.format(Locale.US, \"%.2f\", value) so ',' never appears as a decimal separator.","Sanitize/validate the path string against ^[MmLlHhVvCcSsQqTtAaZz0-9,\\s.+-]+$ plus a float-parse pass before handing it to the parser.","Keep parser calls in a try-catch with a safe fallback path so bad input degrades gracefully instead of crashing."],"exampleFix":"// before\nString d = \"M\" + x + \",\" + y + \" L\" + x2; // y='-5' -> token '..' or '--5' possible\nPathParser.createNodesFromPathData(d);\n\n// after\nString d = String.format(Locale.US, \"M%f,%f L%f,%f\", x, y, x2, y2);\nPathDataNode[] nodes;\ntry {\n    nodes = PathParser.createNodesFromPathData(d);\n} catch (RuntimeException e) {\n    nodes = PathParser.createNodesFromPathData(\"M0,0\"); // fallback\n}","handlingStrategy":"validation","validationCode":"// Verify every token the parser will extract is a valid float\nboolean tokensAreFloats(String d) {\n    for (String tok : d.split(\"[MmLlHhVvCcSsQqTtAaZz,\\\\s]+\")) {\n        if (tok.isEmpty()) continue;\n        if (!tok.matches(\"[+-]?(\\\\d+\\\\.?\\\\d*|\\\\.\\\\d+)\")) return false;\n    }\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n    nodes = PathParser.createNodesFromPathData(pathData);\n} catch (RuntimeException e) {\n    // message quotes the offending string; log it and use a safe default\n    nodes = new PathDataNode[0];\n}","preventionTips":["Never build path strings by naive concatenation without separators between numbers.","Avoid scientific notation and locale-formatted decimals in path data.","Sanitize imported SVG exports in a vector editor before extracting the 'd' attribute."],"tags":["svg","path-parsing","number-format","drawable","android"],"backgroundTag":null,"analyzedSha":"224db48f8af897a930b810a6b6fc55af8cef0d57","analyzedAt":"2026-08-14T10:09:28.455Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}