{"record":{"id":"1fa3d224535a2954","repo":"HMCL-dev/HMCL","slug":"the-world-has-been-locked","errorCode":null,"errorMessage":"The world  has been locked","messagePattern":"The world  has been locked","errorType":"exception","errorClass":"WorldLockedException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/game/World.java","lineNumber":368,"sourceCode":"            }\n            new World(worldDir).rename(name);\n        } else if (Files.isDirectory(file)) {\n            FileUtils.copyDirectory(file, worldDir);\n        }\n    }\n\n    public void export(Path zip, String worldName) throws IOException {\n        if (!Files.isDirectory(file))\n            throw new IOException();\n\n        try (Zipper zipper = new Zipper(zip)) {\n            zipper.putDirectory(file, worldName);\n        }\n    }\n\n    public void delete() throws IOException {\n        if (isLocked()) {\n            throw new WorldLockedException(\"The world \" + getFile() + \" has been locked\");\n        }\n        FileUtils.forceDelete(file);\n    }\n\n    public void copy(String newName) throws IOException {\n        if (!Files.isDirectory(file)) {\n            throw new IOException(\"Not a valid world directory\");\n        }\n\n        if (isLocked()) {\n            throw new WorldLockedException(\"The world \" + getFile() + \" has been locked\");\n        }\n\n        Path newPath = file.resolveSibling(newName);\n        FileUtils.copyDirectory(file, newPath, path -> !path.contains(\"session.lock\"));\n        World newWorld = new World(newPath);\n        newWorld.rename(newName);\n    }","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/game/World.java#L350-L386","documentation":"World.delete() refuses to delete a Minecraft save directory while a session.lock file lock is held on it. HMCL guards deletion this way so it never yanks the world out from under a running game process that has the world open. It throws WorldLockedException (an IOException subclass) carrying the world directory path.","triggerScenarios":"Calling World.delete() on a world whose session.lock is currently locked by another process (typically a running Minecraft instance), i.e. World.isLocked() returns true at the moment of the call.","commonSituations":"User tries to delete a world from the launcher while that world's Minecraft instance is still running or crashed without releasing its lock; an orphaned JVM holds the file lock; on Windows the file is also held open by an antivirus or backup tool.","solutions":["Close the running Minecraft instance that has this world open, then retry delete()","Check for orphaned Java processes still holding session.lock and kill them (lsof/handle.exe)","Close other programs (antivirus scan, backup sync) holding session.lock open and retry","Catch WorldLockedException and surface a 'world is in use' message instead of retrying delete"],"exampleFix":"// before\nworld.delete();\n// after\ntry {\n    world.delete();\n} catch (WorldLockedException e) {\n    UI.warn(\"World is in use by a running game; close it first.\");\n}","handlingStrategy":"try-catch","validationCode":"if (world.isLocked()) {\n    throw new IllegalStateException(\"World is in use; close the game first\");\n}\nworld.delete();","typeGuard":null,"tryCatchPattern":"try {\n    world.delete();\n} catch (WorldLockedException e) {\n    notifyUserWorldInUse(world.getFile().toString());\n}","preventionTips":["Close the Minecraft instance before deleting a world","Check world.isLocked() before destructive operations","Kill orphaned java processes holding session.lock","Avoid running backups/AV that keep session.lock open during deletes"],"tags":["file-lock","minecraft","world-management","io"],"backgroundTag":"file-already-in-use","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}