bumptech/glide · error · FileNotFoundException
InputStream is null for {uri}
Error message
InputStream is null for {uri} What it means
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.
Source
Thrown at library/src/main/java/com/bumptech/glide/load/data/StreamLocalUriFetcher.java:70
public StreamLocalUriFetcher(ContentResolver resolver, Uri uri) {
super(resolver, uri);
}
/**
* useMediaStoreApisIfAvailable is part of an experiment and the constructor can be removed in a
* future version.
*/
public StreamLocalUriFetcher(
ContentResolver resolver, Uri uri, boolean useMediaStoreApisIfAvailable) {
super(resolver, uri, useMediaStoreApisIfAvailable);
}
@Override
protected InputStream loadResource(Uri uri, ContentResolver contentResolver)
throws FileNotFoundException {
InputStream inputStream = loadResourceFromUri(uri, contentResolver);
if (inputStream == null) {
throw new FileNotFoundException("InputStream is null for " + uri);
}
return inputStream;
}
private InputStream loadResourceFromUri(Uri uri, ContentResolver contentResolver)
throws FileNotFoundException {
switch (URI_MATCHER.match(uri)) {
case ID_CONTACTS_CONTACT:
return openContactPhotoInputStream(contentResolver, uri);
case ID_CONTACTS_LOOKUP:
case ID_LOOKUP_BY_PHONE:
// If it was a Lookup uri then resolve it first, then continue loading the contact uri.
uri = ContactsContract.Contacts.lookupContact(contentResolver, uri);
if (uri == null) {
throw new FileNotFoundException("Contact cannot be found");
}
return openContactPhotoInputStream(contentResolver, uri);
case ID_CONTACTS_THUMBNAIL:View on GitHub (pinned to eb14a895d8)
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
Example fix
// before
Glide.with(context).load(pickedUri).into(imageView);
// after — verify and handle
if (contentResolver.query(pickedUri, null, null, null, null) != null) {
Glide.with(context).load(pickedUri).error(R.drawable.placeholder).into(imageView);
} else {
imageView.setImageResource(R.drawable.placeholder);
} Defensive patterns
Strategy: try-catch
Validate before calling
// Verify content exists before loading
private boolean uriHasContent(ContentResolver cr, Uri uri) {
try (Cursor c = cr.query(uri, null, null, null, null)) {
return c != null && c.getCount() > 0;
} catch (Exception e) {
return false;
}
}
if (uriHasContent(getContentResolver(), uri)) {
Glide.with(context).load(uri).into(imageView);
} Try / catch
Glide.with(context)
.load(uri)
.error(R.drawable.placeholder)
.fallback(R.drawable.placeholder)
.listener(new RequestListener<Drawable>() {
@Override public boolean onLoadFailed(GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
for (Throwable cause : e.getRootCauses()) {
if (cause instanceof FileNotFoundException) {
Log.w(TAG, "Content not found for " + model);
}
}
return false;
}
@Override public boolean onResourceReady(Drawable r, Object m, Target<Drawable> t, DataSource d, boolean i) { return false; }
})
.into(imageView); Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- FileDescriptor is null for: {uri}
- FileDescriptor is null for: {uri}
- Contact cannot be found
- Constructor for {} accepts too many parameters, it should ac
- Unrecognized type: {}
AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14).
Data as JSON: /api/errors/7d196873f431bc17.
Report an issue: GitHub.