{"record":{"id":"20d8f6d558b386db","repo":"HMCL-dev/HMCL","slug":"name-existing","errorCode":null,"errorMessage":"name existing","messagePattern":"name existing","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/game/ModpackHelper.java","lineNumber":184,"sourceCode":"        ExceptionalConsumer<Exception, ?> failure = ex -> {\n            if (ex instanceof ModpackCompletionException && !(ex.getCause() instanceof FileNotFoundException)) {\n                success.run();\n                // This is tolerable and we will not delete the game\n            }\n        };\n\n        return new ServerModpackRemoteInstallTask(repository.getDependency(), manifest, instanceId)\n                .whenComplete(Schedulers.defaultScheduler(), success, failure)\n                .withStagesHints(new Task.StagesHint(\"hmcl.modpack\"), new Task.StagesHint(\"hmcl.modpack.download\", List.of(\"hmcl.install.assets\", \"hmcl.install.libraries\")));\n    }\n\n    public static boolean isExternalGameNameConflicts(String name) {\n        return Files.exists(Paths.get(\"externalgames\").resolve(name));\n    }\n\n    public static Task<?> getInstallManuallyCreatedModpackTask(Path zipFile, String name, Charset charset) {\n        if (isExternalGameNameConflicts(name)) {\n            throw new IllegalArgumentException(\"name existing\");\n        }\n\n        return new ManuallyCreatedModpackInstallTask(zipFile, charset, name)\n                .thenAcceptAsync(Schedulers.javafx(), location -> {\n                    GameDirectory newGameDirectory = new GameDirectory(\n                            GameDirectoryManager.newGameDirectoryId(),\n                            LocalizedText.plain(name),\n                            PortablePath.fromPath(location));\n                    GameDirectoryManager.addLocalGameDirectory(newGameDirectory);\n                    GameDirectoryManager.setSelectedGameDirectory(newGameDirectory);\n                });\n    }\n\n    public static Task<?> getInstallTask(HMCLGameRepository repository, Path zipFile, GameInstanceID instanceId, Modpack modpack, @Nullable String iconUrl) {\n        ExceptionalRunnable<?> success = () -> {\n            repository.refresh();\n            repository.getInstance(instanceId).enableIsolation();\n        };","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/game/ModpackHelper.java#L166-L202","documentation":"Thrown by getInstallManuallyCreatedModpackTask as an IllegalArgumentException when the requested name for a manually created modpack conflicts with an existing external game directory. The check is isExternalGameNameConflicts(name), which tests whether the 'externalgames/<name>' directory already exists on disk. HMCL refuses to install over an existing external game to avoid clobbering it.","triggerScenarios":"Calling getInstallManuallyCreatedModpackTask(zipFile, name, charset) with a name such that Paths.get(\"externalgames\").resolve(name) exists.","commonSituations":"User picks a modpack name identical to one already installed (or previously created) in the externalgames folder; leftover directory from a failed earlier install; re-running an install flow without changing the name; name differing only in characters that normalize to the same path.","solutions":["Choose a different, unique name for the modpack instance","Check isExternalGameNameConflicts(name) before installing and prompt the user for a new name","If the old directory is unwanted, delete the externalgames/<name> directory first","Verify no stale/orphaned directory from a previous failed install remains"],"exampleFix":"// before\nTask<?> task = ModpackHelper.getInstallManuallyCreatedModpackTask(zip, \"MyPack\", charset);\n// after\nif (!ModpackHelper.isExternalGameNameConflicts(\"MyPack\")) {\n    Task<?> task = ModpackHelper.getInstallManuallyCreatedModpackTask(zip, \"MyPack\", charset);\n} else {\n    throw new IllegalStateException(\"Name 'MyPack' already in use; pick another name\");\n}","handlingStrategy":"validation","validationCode":"if (ModpackHelper.isExternalGameNameConflicts(name)) {\n    throw new IllegalStateException(\"Modpack name '\" + name + \"' is already in use\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    Task<?> task = ModpackHelper.getInstallManuallyCreatedModpackTask(zipFile, name, charset);\n} catch (IllegalArgumentException e) {\n    ui.promptNameAlreadyExists(name); // ask user for another name\n}","preventionTips":["Always call isExternalGameNameConflicts before installing","Auto-generate unique names (append a counter) when a collision is detected","Clean up stale directories under externalgames after failed installs"],"tags":["java","file-already-exists","naming-conflict"],"backgroundTag":"file-already-exists","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"}