bumptech/glide · error · IOException

File unsuitable for memory mapping

Error message

File unsuitable for memory mapping

What it means

Thrown by ByteBufferUtil.fromFile(File) when file.length() == 0. Memory-mapping a zero-length file is undefined/unsafe on some Android versions (see b/67710449 — FileChannel.map can crash or return an unusable buffer), so Glide rejects empty files explicitly.

Source

Thrown at library/src/main/java/com/bumptech/glide/util/ByteBufferUtil.java:41

  private static final AtomicReference<byte[]> BUFFER_REF = new AtomicReference<>();

  private ByteBufferUtil() {
    // Utility class.
  }

  @NonNull
  public static ByteBuffer fromFile(@NonNull File file) throws IOException {
    RandomAccessFile raf = null;
    FileChannel channel = null;
    try {
      long fileLength = file.length();
      // See #2240.
      if (fileLength > Integer.MAX_VALUE) {
        throw new IOException("File too large to map into memory");
      }
      // See b/67710449.
      if (fileLength == 0) {
        throw new IOException("File unsuitable for memory mapping");
      }

      raf = new RandomAccessFile(file, "r");
      channel = raf.getChannel();
      return channel.map(FileChannel.MapMode.READ_ONLY, 0, fileLength).load();
    } finally {
      if (channel != null) {
        try {
          channel.close();
        } catch (IOException e) {
          // Ignored.
        }
      }
      if (raf != null) {
        try {
          raf.close();
        } catch (IOException e) {
          // Ignored.

View on GitHub (pinned to eb14a895d8)

Solutions

  1. Validate file.length() > 0 before loading and surface a fallback/error drawable
  2. Delete and regenerate empty cache files; clear Glide's disk cache (Glide.get(ctx).clearDiskCache()) if corruption is widespread
  3. Ensure the producer of the file fully writes/closes it before Glide reads it
  4. Use .error(fallbackDrawable) so an empty-file failure degrades gracefully

Example fix

// before
Glide.with(ctx).load(suspectFile).into(imageView)

// after
if (suspectFile.exists() && suspectFile.length() > 0) {
  Glide.with(ctx).load(suspectFile).into(imageView)
} else {
  imageView.setImageResource(R.drawable.placeholder)
}
Defensive patterns

Strategy: validation

Validate before calling

if (file.exists() && file.length() > 0) {
  Glide.with(ctx).load(file).into(imageView)
} else {
  imageView.setImageResource(R.drawable.placeholder)
}

Prevention

When it happens

Trigger: Loading a File model that is empty: a partially-written download, a placeholder/touch file, a truncated cache entry, or a file created by mistake. Any Glide load path that resolves to ByteBufferUtil.fromFile on a zero-byte file triggers this.

Common situations: A download/cache write that was interrupted, leaving a 0-byte file on disk; corrupt or empty cache entries after an app crash; passing a File obtained from a content resolver that resolved to nothing.

Related errors


AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14). Data as JSON: /api/errors/e09e9d8d821055dc. Report an issue: GitHub.