{"record":{"id":"bb4146bc1a3e7d60","repo":"HMCL-dev/HMCL","slug":"instanceid","errorCode":null,"errorMessage":"${instanceId}","messagePattern":"\\$\\{instanceId\\}","errorType":"exception","errorClass":"NoSuchGameInstanceException","httpStatus":null,"severity":"error","filePath":"HMCLCore/src/main/java/org/jackhuang/hmcl/game/DefaultGameRepositoryDraft.java","lineNumber":129,"sourceCode":"    /// {@inheritDoc}\n    @Override\n    public boolean isCommitted() {\n        return state == GameRepositoryDraft.State.COMMITTED;\n    }\n\n    /// {@inheritDoc}\n    @Override\n    public void put(GameInstanceManifest manifest) throws IOException {\n        checkOpen();\n        putManifest(manifest, true);\n    }\n\n    /// {@inheritDoc}\n    @Override\n    public void putPrimaryJar(GameInstanceID instanceId, Path source) throws IOException {\n        checkOpen();\n        if (!manifests.containsKey(instanceId)) {\n            throw new NoSuchGameInstanceException(instanceId);\n        }\n\n        Path normalizedSource = source.toAbsolutePath().normalize();\n        if (!Files.isRegularFile(normalizedSource)) {\n            throw new IOException(\"Primary JAR source is not a regular file: \" + normalizedSource);\n        }\n\n        Path target = getPrimaryJarTarget(instanceId);\n        if (normalizedSource.equals(target)) {\n            primaryJarSources.remove(instanceId);\n        } else {\n            primaryJarSources.put(instanceId, normalizedSource);\n        }\n    }\n\n    /// {@inheritDoc}\n    @Override\n    public void remove(GameInstanceID instanceId) {","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCLCore/src/main/java/org/jackhuang/hmcl/game/DefaultGameRepositoryDraft.java#L111-L147","documentation":"putPrimaryJar() on DefaultGameRepositoryDraft stages a replacement primary JAR for an existing instance, but first validates that instanceId refers to a manifest the draft knows about. If not, it throws NoSuchGameInstanceException whose message is the instance id. The draft only tracks instances from its base snapshot plus ones created via this draft — unknown ids are rejected immediately.","triggerScenarios":"Calling putPrimaryJar with a GameInstanceID that was never created in the repository, was created by a different draft/session, was removed, or is a typo of a real id; also when the base repository was modified elsewhere after the snapshot was taken.","commonSituations":"Stale references held across draft sessions; an instance deleted by another part of the app while a draft is open; misspelled or lowercase/uppercase mismatched instance ids; tests/automation using fabricated ids.","solutions":["Verify the instance exists with repository.getInstance(id) or by checking the draft's manifests before calling putPrimaryJar","Create the instance via draft.put(...) first if it is genuinely new, then stage its primary jar","Catch NoSuchGameInstanceException and prompt the user to select a valid instance rather than assuming the id is valid","Reload the repository snapshot if instances may have changed since the draft was opened"],"exampleFix":"// before\ndraft.putPrimaryJar(instanceId, jarPath); // throws if unknown\n// after\nif (draft.hasManifest(instanceId)) { // or check via snapshot\n    draft.putPrimaryJar(instanceId, jarPath);\n} else {\n    throw new IllegalArgumentException(\"Unknown instance: \" + instanceId);\n}","handlingStrategy":"type-guard","validationCode":"boolean exists = repository.getInstanceIds().contains(instanceId);\nif (!exists) throw new IllegalArgumentException(\"Unknown instance: \" + instanceId);","typeGuard":"boolean knownInstance = draft.manifests().stream().anyMatch(m -> m.id().equals(instanceId));","tryCatchPattern":"try {\n    draft.putPrimaryJar(instanceId, jar);\n} catch (NoSuchGameInstanceException e) {\n    LOG.warning(\"Instance not in this draft: \" + e.getMessage());\n}","preventionTips":["Reopen the draft after instances change elsewhere","Look up ids from the repository instead of caching them across sessions","Compare ids case-sensitively — GameInstanceID is exact-match"],"tags":["instance-not-found","invalid-id","minecraft-instance"],"backgroundTag":"record-not-found","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"}