{"record":{"id":"7d196873f431bc17","repo":"bumptech/glide","slug":"inputstream-is-null-for-uri","errorCode":null,"errorMessage":"InputStream is null for {uri}","messagePattern":"InputStream is null for (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/load/data/StreamLocalUriFetcher.java","lineNumber":70,"sourceCode":"  public StreamLocalUriFetcher(ContentResolver resolver, Uri uri) {\n    super(resolver, uri);\n  }\n\n  /**\n   * useMediaStoreApisIfAvailable is part of an experiment and the constructor can be removed in a\n   * future version.\n   */\n  public StreamLocalUriFetcher(\n      ContentResolver resolver, Uri uri, boolean useMediaStoreApisIfAvailable) {\n    super(resolver, uri, useMediaStoreApisIfAvailable);\n  }\n\n  @Override\n  protected InputStream loadResource(Uri uri, ContentResolver contentResolver)\n      throws FileNotFoundException {\n    InputStream inputStream = loadResourceFromUri(uri, contentResolver);\n    if (inputStream == null) {\n      throw new FileNotFoundException(\"InputStream is null for \" + uri);\n    }\n    return inputStream;\n  }\n\n  private InputStream loadResourceFromUri(Uri uri, ContentResolver contentResolver)\n      throws FileNotFoundException {\n    switch (URI_MATCHER.match(uri)) {\n      case ID_CONTACTS_CONTACT:\n        return openContactPhotoInputStream(contentResolver, uri);\n      case ID_CONTACTS_LOOKUP:\n      case ID_LOOKUP_BY_PHONE:\n        // If it was a Lookup uri then resolve it first, then continue loading the contact uri.\n        uri = ContactsContract.Contacts.lookupContact(contentResolver, uri);\n        if (uri == null) {\n          throw new FileNotFoundException(\"Contact cannot be found\");\n        }\n        return openContactPhotoInputStream(contentResolver, uri);\n      case ID_CONTACTS_THUMBNAIL:","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/load/data/StreamLocalUriFetcher.java#L52-L88","documentation":"StreamLocalUriFetcher resolves a local content Uri to an InputStream via loadResourceFromUri, which delegates to ContentResolver methods like openInputStream or openContactPhotoInputStream. If the resolver returns null (content not found, provider does not support the operation, or insufficient permissions), Glide throws a FileNotFoundException with the Uri in the message.","triggerScenarios":"Loading a content:// Uri for a resource that no longer exists. The content provider returns null from openInputStream for the given Uri. Loading from a FileProvider Uri after the file was deleted. Contact photo Uri for a contact with no photo.","commonSituations":"Loading images picked via the photo picker or ACTION_PICK that have since been moved or deleted. Stale Uri references persisted across app restarts. Missing runtime permissions (READ_EXTERNAL_STORAGE, READ_CONTACTS). Content provider does not implement openInputStream for the URI type.","solutions":["Verify the Uri resolves by querying the ContentResolver before loading","Ensure all required runtime permissions are granted before attempting to load","Use .error() and .fallback() to show a placeholder when content is unavailable","Handle FileNotFoundException in RequestListener to log or report missing content"],"exampleFix":"// before\nGlide.with(context).load(pickedUri).into(imageView);\n// after — verify and handle\nif (contentResolver.query(pickedUri, null, null, null, null) != null) {\n  Glide.with(context).load(pickedUri).error(R.drawable.placeholder).into(imageView);\n} else {\n  imageView.setImageResource(R.drawable.placeholder);\n}","handlingStrategy":"try-catch","validationCode":"// Verify content exists before loading\nprivate boolean uriHasContent(ContentResolver cr, Uri uri) {\n  try (Cursor c = cr.query(uri, null, null, null, null)) {\n    return c != null && c.getCount() > 0;\n  } catch (Exception e) {\n    return false;\n  }\n}\nif (uriHasContent(getContentResolver(), uri)) {\n  Glide.with(context).load(uri).into(imageView);\n}","typeGuard":null,"tryCatchPattern":"Glide.with(context)\n  .load(uri)\n  .error(R.drawable.placeholder)\n  .fallback(R.drawable.placeholder)\n  .listener(new RequestListener<Drawable>() {\n    @Override public boolean onLoadFailed(GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {\n      for (Throwable cause : e.getRootCauses()) {\n        if (cause instanceof FileNotFoundException) {\n          Log.w(TAG, \"Content not found for \" + model);\n        }\n      }\n      return false;\n    }\n    @Override public boolean onResourceReady(Drawable r, Object m, Target<Drawable> t, DataSource d, boolean i) { return false; }\n  })\n  .into(imageView);","preventionTips":["Verify content Uris resolve via ContentResolver#query before loading","Ensure all required runtime permissions are granted","Do not persist content Uris across sessions without re-validating","Always provide .error() and .fallback() placeholders for local Uri loads"],"tags":["glide","uri","content-resolver","file-not-found"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}