{"record":{"id":"c853aa3aac539666","repo":"didi/DoKit","slug":"no-package-provided-data-uri","errorCode":null,"errorMessage":"No package provided: \" + data.uri","messagePattern":"No package provided: \" \\+ data\\.uri","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"warning","filePath":"Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Utils.java","lineNumber":338,"sourceCode":"\n  static boolean isWebPFile(InputStream stream) throws IOException {\n    byte[] fileHeaderBytes = new byte[WEBP_FILE_HEADER_SIZE];\n    boolean isWebPFile = false;\n    if (stream.read(fileHeaderBytes, 0, WEBP_FILE_HEADER_SIZE) == WEBP_FILE_HEADER_SIZE) {\n      // 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);","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit/src/main/java/com/didichuxing/doraemonkit/picasso/Utils.java#L320-L356","documentation":"Utils.getResourceId(Resources, Request) resolves an android.resource:// URI back to a resource ID for resource-request loading. If the URI has no authority segment (data.uri.getAuthority() == null) there is no package name to look the resource up in, so the method throws FileNotFoundException('No package provided: <uri>'). It surfaces as the error path of the image request (typically wrapped in the request's error handling) rather than a crash.","triggerScenarios":"Passing a malformed resource URI to Picasso, e.g. Uri.parse(\"android.resource://\" + resId) without a package, or \"android.resource:///drawable/name\" — the authority (package) component is empty.","commonSituations":"Hand-building android.resource URIs via string concatenation and forgetting the package segment; copying a content:// or file:// pattern and adapting it incorrectly; a URI produced by another component that drops the authority.","solutions":["Use the supported resource forms: picasso.load(R.drawable.foo) directly, or a correctly formed URI Uri.parse(\"android.resource://com.example.app/drawable/foo\").","Prefer the resource-ID overload whenever the resource is local — it avoids URI parsing entirely.","If constructing URIs, validate them (uri.getAuthority() != null) before handing them to Picasso."],"exampleFix":"// before\nUri uri = Uri.parse(\"android.resource:///\" + R.drawable.foo); // no package\npicasso.load(uri).into(imageView);\n\n// after\npicasso.load(R.drawable.foo).into(imageView);\n// or\nUri uri = new Uri.Builder().scheme(\"android.resource\").authority(context.getPackageName())\n        .appendPath(\"drawable\").appendPath(\"foo\").build();\npicasso.load(uri).into(imageView);","handlingStrategy":"validation","validationCode":"boolean isValidResourceUri(Uri uri) {\n    return \"android.resource\".equals(uri.getScheme()) && uri.getAuthority() != null;\n}\nif (!isValidResourceUri(uri)) uri = fallbackLocalRes;","typeGuard":null,"tryCatchPattern":"FileNotFoundException surfaces via the request error path — attach .error(resId) or a Target/onBitmapFailed handler and log the offending URI.","preventionTips":["Prefer picasso.load(resId) for local resources.","Build resource URIs with Uri.Builder (authority = packageName) instead of string concatenation.","Validate scheme+authority for URIs received from external sources."],"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"}