{"record":{"id":"6034c67950c158f1","repo":"HMCL-dev/HMCL","slug":"failed-to-find-current-hmcl-location-6034c6","errorCode":null,"errorMessage":"Failed to find current HMCL location","messagePattern":"Failed to find current HMCL location","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"HMCL/src/main/java/org/jackhuang/hmcl/util/Restarter.java","lineNumber":37,"sourceCode":"\nimport org.jackhuang.hmcl.upgrade.UpdateHandler;\nimport org.jackhuang.hmcl.util.io.JarUtils;\n\nimport java.io.IOException;\nimport java.nio.file.Path;\n\nimport static org.jackhuang.hmcl.util.logging.Logger.LOG;\n\n/// @author Glavo\npublic final class Restarter {\n\n    /// Restart the current application.\n    public static void restartSelf() throws IOException {\n        LOG.info(\"Restarting HMCL\");\n\n        Path thisJar = JarUtils.thisJarPath();\n        if (thisJar == null) {\n            throw new IOException(\"Failed to find current HMCL location\");\n        }\n\n        UpdateHandler.startJava(thisJar);\n    }\n\n    private Restarter() {\n    }\n}\n","sourceCodeStart":19,"sourceCodeEnd":46,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/util/Restarter.java#L19-L46","documentation":"Restarter.restartSelf restarts the application by resolving the current JAR and invoking UpdateHandler.startJava on it. When JarUtils.thisJarPath() returns null the current JAR location cannot be determined, so restart is impossible and this IOException is thrown.","triggerScenarios":"Calling Restarter.restartSelf() when the process was not launched from a discoverable JAR file (exploded classes, custom classloader, module path, or packed-in-memory launch).","commonSituations":"Running HMCL from an IDE or test harness and clicking a 'restart' action; launching through a wrapper that loads classes without a file-backed JAR.","solutions":["Launch HMCL via java -jar HMCL.jar so its location is resolvable","Guard the restart call: check JarUtils.thisJarPath() != null before offering restart to the user","If embedding, provide a real JAR file path and avoid reflective bootstrapping","Update to a newer HMCL that may support your launch layout"],"exampleFix":"// before\nif (userClickedRestart) Restarter.restartSelf();\n// after\nif (userClickedRestart && JarUtils.thisJarPath() != null) {\n    Restarter.restartSelf();\n} else {\n    LOG.warning(\"Restart unavailable: cannot locate application jar\");\n}","handlingStrategy":"type-guard","validationCode":"if (JarUtils.thisJarPath() == null) {\n    LOG.warning(\"Restart unavailable: application jar not located\");\n    return;\n}\nRestarter.restartSelf();","typeGuard":"boolean restartable() {\n    return JarUtils.thisJarPath() != null;\n}","tryCatchPattern":"try {\n    Restarter.restartSelf();\n} catch (IOException e) {\n    LOG.warning(\"Restart failed: \" + e.getMessage());\n    // surface 'please restart manually' to the user\n}","preventionTips":["Only enable restart UI actions when running from a JAR","In test harnesses, stub restartSelf instead of exercising it","Prefer the official launcher script over IDE or wrapper launches"],"tags":["jar","restart","classpath"],"backgroundTag":"file-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"}