libgdx/libgdx · error · GdxRuntimeException
Cannot delete an internal file:
Error message
Cannot delete an internal file:
What it means
GwtFileHandle.delete() unconditionally throws 'Cannot delete an internal file: <path>'. Preloaded assets are baked into the application bundle and immutable from JavaScript; the GWT backend exposes no deletion. The message text says 'internal file' because only Internal/Classpath handles can exist in this backend.
Source
Thrown at backends/gdx-backends-gwt/src/com/badlogic/gdx/backends/gwt/GwtFileHandle.java:365
public FileHandle sibling (String name) {
return parent().child(fixSlashes(name));
}
/** @throws GdxRuntimeException if this file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file. */
public void mkdirs () {
throw new GdxRuntimeException("Cannot mkdirs with an internal file: " + file);
}
/** Returns true if the file exists. On Android, a {@link FileType#Classpath} or {@link FileType#Internal} handle to a
* directory will always return false. */
public boolean exists () {
return preloader.contains(file);
}
/** Deletes this file or empty directory and returns success. Will not delete a directory that has children.
* @throws GdxRuntimeException if this file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file. */
public boolean delete () {
throw new GdxRuntimeException("Cannot delete an internal file: " + file);
}
/** Deletes this file or directory and all children, recursively.
* @throws GdxRuntimeException if this file handle is a {@link FileType#Classpath} or {@link FileType#Internal} file. */
public boolean deleteDirectory () {
throw new GdxRuntimeException("Cannot delete an internal file: " + file);
}
/** Copies this file or directory to the specified file or directory. If this handle is a file, then 1) if the destination is a
* file, it is overwritten, or 2) if the destination is a directory, this file is copied into it, or 3) if the destination
* doesn't exist, {@link #mkdirs()} is called on the destination's parent and this file is copied into it with a new name. If
* this handle is a directory, then 1) if the destination is a file, GdxRuntimeException is thrown, or 2) if the destination is
* a directory, this directory is copied into it recursively, overwriting existing files, or 3) if the destination doesn't
* exist, {@link #mkdirs()} is called on the destination and this directory is copied into it recursively.
* @throws GdxRuntimeException if the destination file handle is a {@link FileType#Classpath} or {@link FileType#Internal}
* file, or copying failed. */
public void copyTo (FileHandle dest) {
throw new GdxRuntimeException("Cannot copy to an internal file: " + dest);View on GitHub (pinned to 97f4086187)
Solutions
- On the web build, 'deletion' means removing a key from Preferences/localStorage — implement it in a platform-specific save manager.
- Branch on Gdx.app.getType() == ApplicationType.WebGL before any delete() call in shared code.
- Audit ported code for delete()/deleteDirectory() usage when adding the GWT target.
Example fix
// before
Gdx.files.local("saves/slot1.json").delete(); // throws on GWT
// after
if (Gdx.app.getType() == ApplicationType.WebGL) {
Gdx.app.getPreferences("saves").remove("slot1").flush();
} else {
Gdx.files.local("saves/slot1.json").delete();
} Defensive patterns
Strategy: validation
Validate before calling
// 'delete' on web means removing a storage key
if (Gdx.app.getType() == ApplicationType.WebGL) {
Gdx.app.getPreferences("saves").remove("slot1").flush();
} else {
Gdx.files.local("saves/slot1.json").delete();
} Type guard
static boolean canDeleteFiles () {
return Gdx.app.getType() != ApplicationType.WebGL;
} Prevention
- Model deletable entities as keys, not files, in shared code.
- Audit save-management features (delete slot, reset game) when porting to GWT.
- delete() and deleteDirectory() both throw on GWT — treat them as one audit item.
When it happens
Trigger: Calling delete() on a FileHandle under GwtApplication — typically save-management code that removes old save files, or cleanup code that deletes temporary files after use.
Common situations: Ported save-slot management (delete save X) that uses file deletion on desktop; cache-clearing code; shared utilities that tidy up temporary assets.
Related errors
- Cannot write to files in GWT backend
- Cannot copy to an internal file:
- Cannot move an internal file:
- FileType '
- file() not supported in GWT backend
AI-assisted analysis of libgdx/libgdx@97f4086187 (2026-08-14).
Data as JSON: /api/errors/999622b63e286a6e.
Report an issue: GitHub.