{"record":{"id":"4b7791a1c61e8ac4","repo":"google/ExoPlayer","slug":"could-not-create-the-export-output-file","errorCode":null,"errorMessage":"Could not create the export output file","messagePattern":"Could not create the export output file","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"demos/transformer/src/main/java/com/google/android/exoplayer2/transformerdemo/TransformerActivity.java","lineNumber":363,"sourceCode":"              @Override\n              public void onError(\n                  Composition composition,\n                  ExportResult exportResult,\n                  ExportException exportException) {\n                TransformerActivity.this.onError(exportException);\n              }\n            })\n        .build();\n  }\n\n  /** Creates a cache file, resetting it if it already exists. */\n  private File createExternalCacheFile(String fileName) throws IOException {\n    File file = new File(getExternalCacheDir(), fileName);\n    if (file.exists() && !file.delete()) {\n      throw new IllegalStateException(\"Could not delete the previous export output file\");\n    }\n    if (!file.createNewFile()) {\n      throw new IllegalStateException(\"Could not create the export output file\");\n    }\n    return file;\n  }\n\n  @RequiresNonNull({\n    \"inputCardView\",\n    \"outputPlayerView\",\n    \"exportStopwatch\",\n    \"progressViewGroup\",\n  })\n  private Composition createComposition(MediaItem mediaItem, @Nullable Bundle bundle)\n      throws PackageManager.NameNotFoundException {\n    EditedMediaItem.Builder editedMediaItemBuilder = new EditedMediaItem.Builder(mediaItem);\n    // For image inputs. Automatically ignored if input is audio/video.\n    editedMediaItemBuilder.setDurationUs(5_000_000).setFrameRate(30);\n    boolean forceAudioTrack = false;\n    if (bundle != null) {\n      ImmutableList<AudioProcessor> audioProcessors = createAudioProcessorsFromBundle(bundle);","sourceCodeStart":345,"sourceCodeEnd":381,"githubUrl":"https://github.com/google/ExoPlayer/blob/dd430f7053a1a3958deea3ead6a0565150c06bfc/demos/transformer/src/main/java/com/google/android/exoplayer2/transformerdemo/TransformerActivity.java#L345-L381","documentation":"Thrown by TransformerActivity.createExternalCacheFile when File.createNewFile() returns false for the export output file. createNewFile fails when the file already exists (deletion was skipped or raced), the parent directory does not exist or is unwritable, or the filesystem rejects creation.","triggerScenarios":"createExternalCacheFile called when the target file already exists and the delete branch was not taken (file.exists() was false at check time but a concurrent creator won the race); getExternalCacheDir() returns a path that was deleted or not yet created; external cache dir full or read-only.","commonSituations":"Rapid repeated exports; device low on storage; external cache dir removed by the system while the activity is in background; file created by a previous crashed run between exists() and createNewFile().","solutions":["Verify getExternalCacheDir() exists and canWrite() before creating the file; call mkdirs() on it if needed","Use a per-run unique file name so createNewFile never collides with a stale file","Free external cache space (context.getExternalCacheDir().listFiles() cleanup) before export","If the file already exists, either reuse it (skip createNewFile) or delete it explicitly and confirm deletion succeeded"],"exampleFix":"// before\nif (!file.createNewFile()) {\n  throw new IllegalStateException(\"Could not create the export output file\");\n}\n\n// after: tolerate an existing (already reset) file and unique-ify on failure\nif (!file.createNewFile() && !file.exists()) {\n  throw new IllegalStateException(\"Could not create the export output file\");\n}","handlingStrategy":"validation","validationCode":"File dir = getExternalCacheDir();\nif (dir == null || (!dir.exists() && !dir.mkdirs()) || !dir.canWrite()) {\n  throw new IllegalStateException(\"External cache dir unavailable\");\n}\n// storage headroom check\nStatFs fs = new StatFs(dir.getAbsolutePath());\nif (fs.getAvailableBytes() < REQUIRED_EXPORT_BYTES) {\n  // notify user instead of letting createNewFile fail\n}","typeGuard":null,"tryCatchPattern":"try {\n  file = createExternalCacheFile(fileName);\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"create\")) {\n    file = new File(getExternalCacheDir(),\n        System.currentTimeMillis() + \"-\" + fileName); // unique fallback\n  } else {\n    throw e;\n  }\n}","preventionTips":["Check external-cache availability and free space before export","Use unique per-run file names so createNewFile never collides","Handle the file step separately from composition building so failures are attributable"],"tags":["android","transformer","file-io","demo"],"backgroundTag":null,"analyzedSha":"dd430f7053a1a3958deea3ead6a0565150c06bfc","analyzedAt":"2026-08-14T12:22:02.982Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}