{"record":{"id":"e09e9d8d821055dc","repo":"bumptech/glide","slug":"file-unsuitable-for-memory-mapping","errorCode":null,"errorMessage":"File unsuitable for memory mapping","messagePattern":"File unsuitable for memory mapping","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/bumptech/glide/util/ByteBufferUtil.java","lineNumber":41,"sourceCode":"  private static final AtomicReference<byte[]> BUFFER_REF = new AtomicReference<>();\n\n  private ByteBufferUtil() {\n    // Utility class.\n  }\n\n  @NonNull\n  public static ByteBuffer fromFile(@NonNull File file) throws IOException {\n    RandomAccessFile raf = null;\n    FileChannel channel = null;\n    try {\n      long fileLength = file.length();\n      // See #2240.\n      if (fileLength > Integer.MAX_VALUE) {\n        throw new IOException(\"File too large to map into memory\");\n      }\n      // See b/67710449.\n      if (fileLength == 0) {\n        throw new IOException(\"File unsuitable for memory mapping\");\n      }\n\n      raf = new RandomAccessFile(file, \"r\");\n      channel = raf.getChannel();\n      return channel.map(FileChannel.MapMode.READ_ONLY, 0, fileLength).load();\n    } finally {\n      if (channel != null) {\n        try {\n          channel.close();\n        } catch (IOException e) {\n          // Ignored.\n        }\n      }\n      if (raf != null) {\n        try {\n          raf.close();\n        } catch (IOException e) {\n          // Ignored.","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/bumptech/glide/blob/eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a/library/src/main/java/com/bumptech/glide/util/ByteBufferUtil.java#L23-L59","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Validate file.length() > 0 before loading and surface a fallback/error drawable","Delete and regenerate empty cache files; clear Glide's disk cache (Glide.get(ctx).clearDiskCache()) if corruption is widespread","Ensure the producer of the file fully writes/closes it before Glide reads it","Use .error(fallbackDrawable) so an empty-file failure degrades gracefully"],"exampleFix":"// before\nGlide.with(ctx).load(suspectFile).into(imageView)\n\n// after\nif (suspectFile.exists() && suspectFile.length() > 0) {\n  Glide.with(ctx).load(suspectFile).into(imageView)\n} else {\n  imageView.setImageResource(R.drawable.placeholder)\n}","handlingStrategy":"validation","validationCode":"if (file.exists() && file.length() > 0) {\n  Glide.with(ctx).load(file).into(imageView)\n} else {\n  imageView.setImageResource(R.drawable.placeholder)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate file.length() > 0 before loading","Clear Glide's disk cache (Glide.get(ctx).clearDiskCache()) if you suspect cache corruption","Ensure files are fully written and closed before Glide reads them"],"tags":["android","glide","io","validation","empty-file"],"backgroundTag":null,"analyzedSha":"eb14a895d8f866e6a08c3e19d50ea3bd2c12c20a","analyzedAt":"2026-08-14T01:43:54.821Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}