{"record":{"id":"caccb1d7eae374b6","repo":"HMCL-dev/HMCL","slug":"game-instance-no-longer-exists","errorCode":null,"errorMessage":"Game instance no longer exists: ","messagePattern":"Game instance no longer exists: ","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/modpack/multimc/MultiMCModpackInstallTask.java","lineNumber":186,"sourceCode":"\n    @Override\n    public boolean doPreExecute() {\n        return true;\n    }\n\n    /// Reserves the instance in a repository draft before preparing tasks that write its root.\n    @Override\n    public void preExecute() throws Exception {\n        DefaultGameRepositoryDraft openedDraft = repository.openDraft();\n        draft = openedDraft;\n        try {\n            // Construction fixes the mode; the captured snapshot only verifies that it is still valid.\n            boolean targetExists = openedDraft.getBaseSnapshot().hasInstance(instanceId);\n            if (this.updateTarget == null && targetExists) {\n                throw new IllegalStateException(\"Game instance already exists: \" + instanceId);\n            }\n            if (this.updateTarget != null && !targetExists) {\n                throw new IllegalStateException(\"Game instance no longer exists: \" + instanceId);\n            }\n\n            openedDraft.put(new GameInstanceManifest(instanceId));\n            newInstallationReserved = this.updateTarget == null;\n        } catch (IOException | RuntimeException e) {\n            try {\n                openedDraft.abort();\n            } catch (IOException cleanupFailure) {\n                e.addSuppressed(cleanupFailure);\n            }\n            draft = null;\n            throw e;\n        }\n\n        // Stage #0: General Setup\n        {\n            Path run = repository.getLayout().getInstanceRoot(instanceId);\n","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/modpack/multimc/MultiMCModpackInstallTask.java#L168-L204","documentation":"In update mode the target instance must still exist when the task runs. preExecute checks the draft's base snapshot and throws if the instance recorded at construction time has disappeared, since there is nothing to update.","triggerScenarios":"Update-mode task executed after the target instance was deleted from disk (manually, by another task, or by a failed prior update) so baseSnapshot.hasInstance(instanceId) returns false.","commonSituations":"User deletes the instance while an update is queued; an earlier failed install removed the instance from disk but the UI still holds a stale reference.","solutions":["Reinstall the modpack as a new installation instead of updating.","Re-check instance existence before constructing/running the update task.","Refresh the instance list so stale references are dropped."],"exampleFix":"// before\ntask = new MultiMCModpackInstallTask(dm, zip, modpack, cfg, staleInstance);\n// after\nif (repository.hasInstance(staleInstance.getId())) {\n    task = new MultiMCModpackInstallTask(dm, zip, modpack, cfg, staleInstance);\n} else {\n    task = new MultiMCModpackInstallTask(dm, zip, modpack, cfg, staleInstance.getId()); // fresh install\n}","handlingStrategy":"validation","validationCode":"if (!repository.hasInstance(instance.getId())) { /* refresh UI / fall back to fresh install */ }","typeGuard":null,"tryCatchPattern":"try { task.run(); } catch (IllegalStateException e) { if (e.getMessage().startsWith(\"Game instance no longer exists\")) { /* reinstall fresh */ } }","preventionTips":["Drop stale instance references after deletions","Re-check existence immediately before running update tasks","Avoid deleting instances while tasks are queued"],"tags":["java","modpack","missing-instance","illegal-state"],"backgroundTag":"resource-not-found","analyzedSha":"24702dc5a0214034f4c27166d5fd30cad08cec19","analyzedAt":"2026-09-10T12:36:46.680Z","contentChangedAt":"2026-09-10T12:36:46.680Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}