scwang90/SmartRefreshLayout · error · RuntimeException
Error in parsing ${pathData}
Error message
Error in parsing ${pathData} What it means
Thrown when PathDataNode.nodesToPath() fails while converting parsed SVG path-data nodes into an android.graphics.Path. The path string was tokenized into nodes, but applying them to the Path object raised a RuntimeException (e.g. malformed command sequence, too few parameters for a command, or an unsupported construct). The original pathData string is embedded in the message to help identify the offending input.
Source
Thrown at refresh-drawable-path/src/main/java/com/scwang/smart/drawable/path/PathParser.java:186
val[k + 5] *= ratioWidth;
val[k + 6] *= ratioHeight;
break;
}
}
}
/**
* @param pathData The string representing a path, the same as "d" string in svg file.
* @return the generated Path object.
*/
public static Path createPathFromPathData(String pathData) {
Path path = new Path();
PathDataNode[] nodes = createNodesFromPathData(pathData);
if (nodes != null) {
try {
PathDataNode.nodesToPath(nodes, path);
} catch (RuntimeException e) {
throw new RuntimeException("Error in parsing " + pathData, e);
}
return path;
}
return null;
}
/**
* @param pathData The string representing a path, the same as "d" string in svg file.
* @return an array of the PathDataNode.
*/
public static PathDataNode[] createNodesFromPathData(String pathData) {
if (pathData == null) {
return null;
}
int start = 0;
int end = 1;
List<PathDataNode> list = new ArrayList<>();View on GitHub (pinned to 224db48f8a)
Solutions
- Validate the 'd' string against the full SVG path grammar before passing it (a lint/regex pass or rendering it in a tool like Inkscape/browser first).
- Check the embedded pathData in the exception message for missing parameters — most often a command letter with fewer numbers than it requires.
- Ensure numbers are formatted with Locale.US ('.' decimal separator) when the string is generated programmatically.
- Wrap createPathFromPathData in a try-catch and fall back to a default drawable/header so one bad path does not crash the app.
- If the path uses advanced SVG features, simplify it (convert arcs/transforms in a vector editor and re-export as plain M/L/C/Z commands).
Example fix
// before
Path path = PathParser.createPathFromPathData("M10,10 L40"); // L needs 2 coords -> crash
// after
Path path;
try {
path = PathParser.createPathFromPathData("M10,10 L40,40");
} catch (RuntimeException e) {
path = new Path(); // or load a bundled fallback vector drawable
} Defensive patterns
Strategy: try-catch
Validate before calling
// Quick sanity check: known commands, balanced params, before calling the parser
boolean looksLikeValidPath(String d) {
if (d == null || d.trim().isEmpty()) return false;
if (!d.matches("[MmLlHhVvCcSsQqTtAaZz0-9,\\s.+-]+")) return false;
return d.trim().matches("^[Mm].*"); // must start with a moveto
}
if (looksLikeValidPath(pathData)) {
path = PathParser.createPathFromPathData(pathData);
} Try / catch
Path path;
try {
path = PathParser.createPathFromPathData(pathData);
} catch (RuntimeException e) {
Log.w(TAG, "Bad path data: " + pathData, e);
path = new Path(); // or a bundled fallback vector
} Prevention
- Treat path-data strings as untrusted input: validate or wrap every programmatic construction.
- Format generated floats with Locale.US to keep '.' as the decimal separator.
- Keep a unit test that parses every hardcoded path string used in the app.
- Prefer importing paths as Android vector drawables rather than parsing raw 'd' strings at runtime.
When it happens
Trigger: Calling PathParser.createPathFromPathData(pathData) with an SVG 'd' string that parses into nodes but fails during Path construction: commands with missing/extra parameters (e.g. 'L' with one coordinate), relative commands that underflow, nested or repeated command letters in wrong order, or locale-generated strings using ',' decimal separators.
Common situations: Hand-writing or dynamically building an SVG path string for a refresh header/footer drawable; copying an SVG 'd' attribute that contains arcs (A) or implicit-repeat syntax not handled identically by this parser; formatting floats with String.format in a locale like de/fr producing '3,5' instead of '3.5'; truncating a path string from a designer's SVG export.
Related errors
- error in parsing "${s}"
- 最多只支持3个子View,Most only support three sub view
- DefaultRefreshHeaderCreator can not return null
- DefaultRefreshFooterCreator can not return null
AI-assisted analysis of scwang90/SmartRefreshLayout@224db48f8a (2026-08-14).
Data as JSON: /api/errors/6e4b1d2891da3e7e.
Report an issue: GitHub.