{"record":{"id":"c0f1ce7ef4f575f8","repo":"bumptech/glide","slug":"contact-cannot-be-found","errorCode":null,"errorMessage":"Contact cannot be found","messagePattern":"Contact cannot be found","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"warning","filePath":"library/src/main/java/com/bumptech/glide/load/data/StreamLocalUriFetcher.java","lineNumber":85,"sourceCode":"      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:\n      case ID_CONTACTS_PHOTO:\n      case UriMatcher.NO_MATCH:\n      default:\n        if (useMediaStoreApisIfAvailable\n            && MediaStoreUtil.isMediaStoreUri(uri)\n            && MediaStoreUtil.isMediaStoreOpenFileApisAvailable()) {\n          return openMediaStoreFileInputStream(uri, contentResolver);\n        } else {\n          return contentResolver.openInputStream(uri);\n        }\n    }\n  }\n\n  private InputStream openContactPhotoInputStream(ContentResolver contentResolver, Uri contactUri) {\n    return ContactsContract.Contacts.openContactPhotoInputStream(","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/load/data/StreamLocalUriFetcher.java#L67-L103","documentation":"When loading a contact photo via a lookup Uri or phone-number lookup Uri, StreamLocalUriFetcher first calls ContactsContract.Contacts.lookupContact to resolve the lookup key to a real contact Uri. If lookupContact returns null, no contact matches the lookup key (the contact was deleted, merged, or the key is invalid), and Glide throws a FileNotFoundException.","triggerScenarios":"Loading a contact photo using a stale ContactsContract.Contacts.CONTENT_LOOKUP_URI from a previous session. The contact was deleted or merged after the lookup Uri was stored. A phone number lookup Uri that does not match any contact.","commonSituations":"Apps that cache contact lookup Uris across sessions. Sync or backup/restore operations that change contact IDs. Contact was deleted by the user or another app between storing the Uri and loading the photo. Phone number lookups for numbers not in the user's contacts.","solutions":["Do not persist contact lookup Uris across sessions; re-resolve from contact ID or lookup key each time","Handle FileNotFoundException gracefully and show a default avatar placeholder","Verify the contact still exists via a fresh lookupContact query before loading the photo","Use .fallback() to show a default person silhouette when no contact photo is available"],"exampleFix":"// before\nGlide.with(context).load(storedLookupUri).into(avatarView);\n// after — re-resolve and handle missing contact\nGlide.with(context)\n  .load(storedLookupUri)\n  .fallback(R.drawable.ic_default_avatar)\n  .error(R.drawable.ic_default_avatar)\n  .into(avatarView);","handlingStrategy":"try-catch","validationCode":"// Verify contact exists before loading photo\nprivate boolean contactExists(ContentResolver cr, Uri lookupUri) {\n  Uri contactUri = ContactsContract.Contacts.lookupContact(cr, lookupUri);\n  return contactUri != null;\n}\nif (contactExists(getContentResolver(), lookupUri)) {\n  Glide.with(context).load(lookupUri).into(avatarView);\n}","typeGuard":null,"tryCatchPattern":"Glide.with(context)\n  .load(lookupUri)\n  .fallback(R.drawable.ic_default_avatar)\n  .error(R.drawable.ic_default_avatar)\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 && cause.getMessage().contains(\"Contact cannot be found\")) {\n          Log.w(TAG, \"Contact no longer exists: \" + 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(avatarView);","preventionTips":["Do not persist contact lookup Uris across sessions; re-resolve each time","Always provide .fallback() with a default avatar for contact photo loads","Handle contact deletion/merge scenarios gracefully in your UI","Verify contacts still exist before attempting to load their photos"],"tags":["glide","contacts","uri","file-not-found"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}