{"record":{"id":"9b37edb4b6ec8ec4","repo":"didi/DoKit","slug":"more-than-two-path-segments-data-uri","errorCode":null,"errorMessage":"More than two path segments: \" + data.uri","messagePattern":"More than two 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":356,"sourceCode":"    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 {\n    if (data.resourceId != 0 || data.uri == null) {\n      return context.getResources();\n    }\n\n    String pkg = data.uri.getAuthority();\n    if (pkg == null) throw new FileNotFoundException(\"No package provided: \" + data.uri);\n    try {\n      PackageManager pm = context.getPackageManager();\n      return pm.getResourcesForApplication(pkg);\n    } catch (PackageManager.NameNotFoundException e) {\n      throw new FileNotFoundException(\"Unable to obtain resources for package: \" + data.uri);\n    }\n  }","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Utils.java#L338-L374","documentation":"Utils.getResourceId(Resources, Request) accepts android.resource:// URIs with at most two path segments (one = numeric ID, two = type/name). With three or more segments there is no defined meaning, so it throws FileNotFoundException('More than two path segments: <uri>').","triggerScenarios":"Passing URIs like android.resource://pkg/drawable-hdpi/ic_logo.png or a nested path android.resource://pkg/a/b/c — anything whose getPathSegments().size() > 2.","commonSituations":"Appending file extensions or qualifiers to a resource name; reusing a file-path-style builder for resource URIs; a share/deep-link pipeline that preserves extra segments.","solutions":["Normalize to exactly two segments: type + name without extension or qualifier (android.resource://pkg/drawable/ic_logo).","Validate segment count before loading if URIs arrive from external sources.","Use picasso.load(resId) when the resource is local and known."],"exampleFix":"// before\nUri uri = Uri.parse(\"android.resource://com.example.app/drawable/ic_logo.png\");\npicasso.load(uri).into(imageView);\n\n// after\nUri uri = Uri.parse(\"android.resource://com.example.app/drawable/ic_logo\");\npicasso.load(uri).into(imageView);","handlingStrategy":"validation","validationCode":"boolean hasValidSegmentCount(Uri uri) {\n    List<String> s = uri.getPathSegments();\n    return s != null && !s.isEmpty() && s.size() <= 2;\n}","typeGuard":null,"tryCatchPattern":"Consume via error callback, log the URI, and retry with a normalized two-segment URI.","preventionTips":["Never append extensions (.png) or qualifier folders to resource URIs.","Canonicalize external URIs down to (type, name) before loading.","Assert segment count in debug builds."],"tags":["android","picasso","uri","resource","parsing"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}