{"record":{"id":"e5f14a24604100db","repo":"bumptech/glide","slug":"package-name-for-source-is-null-or-empty","errorCode":null,"errorMessage":"Package name for {source} is null or empty","messagePattern":"Package name for (.+?) is null or empty","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java","lineNumber":75,"sourceCode":"  private final Context context;\n\n  public ResourceDrawableDecoder(Context context) {\n    this.context = context.getApplicationContext();\n  }\n\n  @Override\n  public boolean handles(@NonNull Uri source, @NonNull Options options) {\n    String scheme = source.getScheme();\n    return scheme != null && scheme.equals(ContentResolver.SCHEME_ANDROID_RESOURCE);\n  }\n\n  @Nullable\n  @Override\n  public Resource<Drawable> decode(\n      @NonNull Uri source, int width, int height, @NonNull Options options) {\n    String packageName = source.getAuthority();\n    if (TextUtils.isEmpty(packageName)) {\n      throw new IllegalStateException(\"Package name for \" + source + \" is null or empty\");\n    }\n    Context targetContext = findContextForPackage(source, packageName);\n    @DrawableRes int resId = findResourceIdFromUri(targetContext, source);\n    // Only use the provided theme if we're loading resources from our package. We can't get themes\n    // from other packages and we don't want to use a theme from our package when loading another\n    // package's resources.\n    Theme theme =\n        Preconditions.checkNotNull(packageName).equals(context.getPackageName())\n            ? options.get(THEME)\n            : null;\n    Drawable drawable =\n        theme == null\n            ? DrawableDecoderCompat.getDrawable(context, targetContext, resId)\n            : DrawableDecoderCompat.getDrawable(context, resId, theme);\n    return NonOwnedDrawableResource.newInstance(drawable);\n  }\n\n  @NonNull","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/load/resource/drawable/ResourceDrawableDecoder.java#L57-L93","documentation":"IllegalStateException thrown by ResourceDrawableDecoder.decode() when source.getAuthority() returns null or empty. The authority segment of an android.resource:// URI must contain the target package name so Glide can locate the resources.","triggerScenarios":"Constructing a Uri with scheme android.resource but a null/empty authority, e.g. Uri.parse(\"android.resource://\"), or building a Uri via Uri.Builder() without calling .authority().","commonSituations":"Programmatically building a resource Uri and forgetting the package. Passing a malformed string to Uri.parse(). Stripping the authority during Uri manipulation.","solutions":["Build resource Uris with the documented form: android.resource://<package>/<type>/<name> or android.resource://<package>/<resId>.","Use ResourceLoader or the integer-resId overload of Glide (Glide.with(ctx).load(R.drawable.foo)) instead of hand-building Uris.","Validate Uri authority before passing to Glide."],"exampleFix":"// before\nUri uri = Uri.parse(\"android.resource/\" + resId); // missing authority\nGlide.with(ctx).load(uri).into(img);\n// after\nUri uri = Uri.parse(\"android.resource://\" + ctx.getPackageName() + \"/\" + resId);\nGlide.with(ctx).load(uri).into(img);","handlingStrategy":"validation","validationCode":"// Validate Uri authority before loading.\nUri uri = ...;\nif (uri == null || TextUtils.isEmpty(uri.getAuthority())\n    || !\"android.resource\".equals(uri.getScheme())) {\n  // reject or build a valid Uri\n  uri = Uri.parse(\"android.resource://\" + ctx.getPackageName() + \"/\" + resId);\n}\nGlide.with(ctx).load(uri).into(img);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include the package in the authority when building android.resource Uris.","Prefer Glide.with(ctx).load(resId) over hand-built Uris.","Validate scheme and authority before loading."],"tags":["uri","drawable","resource","validation","android"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}