{"record":{"id":"11ad7d1b88bf2398","repo":"didi/DoKit","slug":"no-path-segments-data-uri","errorCode":null,"errorMessage":"No path segments: \" + data.uri","messagePattern":"No path segments: \" \\+ data\\.uri","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"warning","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Utils.java","lineNumber":343,"sourceCode":"      // If a file's header starts with RIFF and end with WEBP, the file is a WebP file\n      isWebPFile = WEBP_FILE_HEADER_RIFF.equals(new String(fileHeaderBytes, 0, 4, \"US-ASCII\"))\n          && WEBP_FILE_HEADER_WEBP.equals(new String(fileHeaderBytes, 8, 4, \"US-ASCII\"));\n    }\n    return isWebPFile;\n  }\n\n  static int getResourceId(Resources resources, Request data) throws FileNotFoundException {\n    if (data.resourceId != 0 || data.uri == null) {\n      return data.resourceId;\n    }\n\n    String pkg = data.uri.getAuthority();\n    if (pkg == null) throw new FileNotFoundException(\"No package provided: \" + data.uri);\n\n    int id;\n    List<String> segments = data.uri.getPathSegments();\n    if (segments == null || segments.isEmpty()) {\n      throw new FileNotFoundException(\"No path segments: \" + data.uri);\n    } else if (segments.size() == 1) {\n      try {\n        id = Integer.parseInt(segments.get(0));\n      } catch (NumberFormatException e) {\n        throw new FileNotFoundException(\"Last path segment is not a resource ID: \" + data.uri);\n      }\n    } else if (segments.size() == 2) {\n      String type = segments.get(0);\n      String name = segments.get(1);\n\n      id = resources.getIdentifier(name, type, pkg);\n    } else {\n      throw new FileNotFoundException(\"More than two path segments: \" + data.uri);\n    }\n    return id;\n  }\n\n  static Resources getResources(Context context, Request data) throws FileNotFoundException {","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Utils.java#L325-L361","documentation":"Utils.getResourceId(Resources, Request) parses the path segments of an android.resource:// URI to find the resource. A URI whose path is empty yields no segments, so there is nothing to resolve (neither a numeric ID nor type/name pair), and the method throws FileNotFoundException('No path segments: <uri>'). Like the other resolution failures it feeds the request's error path.","triggerScenarios":"Passing a URI such as android.resource://com.example.app (empty path) or android.resource://com.example.app/ to picasso.load(); trailing-segment stripped by string manipulation.","commonSituations":"Building the URI from authority only and forgetting appendPath; a URI builder bug that drops path components; dynamically assembled URIs where the resource name variable was empty.","solutions":["Include the path: android.resource://<package>/<type>/<name> or android.resource://<package>/<numeric_id>.","Prefer picasso.load(resId) for local resources.","Add a debug assertion that uri.getPathSegments() is non-empty before loading."],"exampleFix":"// before\nUri uri = Uri.parse(\"android.resource://com.example.app/\"); // empty path\npicasso.load(uri).into(imageView);\n\n// after\nUri uri = Uri.parse(\"android.resource://com.example.app/drawable/foo\");\npicasso.load(uri).into(imageView);","handlingStrategy":"validation","validationCode":"boolean hasPathSegments(Uri uri) {\n    List<String> s = uri.getPathSegments();\n    return s != null && !s.isEmpty();\n}","typeGuard":null,"tryCatchPattern":"Handle in the request error callback: log the URI and fall back to a bundled resource.","preventionTips":["Always append type+name (or numeric ID) path segments.","Unit-test URI builders to assert segment structure.","Use Uri.Builder.appendPath so empty components are obvious."],"tags":["android","picasso","uri","resource","malformed-input"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}