{"record":{"id":"b327c60dc71b6e23","repo":"HMCL-dev/HMCL","slug":"failed-to-find-current-hmcl-location-b327c6","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/upgrade/UpdateHandler.java","lineNumber":266,"sourceCode":"        }).collect(Collectors.joining(\" \"));\n    }\n\n    private static Optional<Path> tryRename(Path path, String newVersion) {\n        String filename = path.getFileName().toString();\n        Matcher matcher = Pattern.compile(\"^(?<prefix>[hH][mM][cC][lL][.-])(?<version>\\\\d+(?:\\\\.\\\\d+)*)(?<suffix>\\\\.[^.]+)$\").matcher(filename);\n        if (matcher.find()) {\n            String newFilename = matcher.group(\"prefix\") + newVersion + matcher.group(\"suffix\");\n            if (!newFilename.equals(filename)) {\n                return Optional.of(path.resolveSibling(newFilename));\n            }\n        }\n        return Optional.empty();\n    }\n\n    private static Path getCurrentLocation() throws IOException {\n        Path path = JarUtils.thisJarPath();\n        if (path == null) {\n            throw new IOException(\"Failed to find current HMCL location\");\n        }\n        return path;\n    }\n\n    // ==== support for old versions ===\n    private static void performMigration() throws IOException {\n        LOG.info(\"Migrating from old versions\");\n\n        Path location = getParentApplicationLocation()\n                .orElseThrow(() -> new IOException(\"Failed to get parent application location\"));\n\n        requestUpdate(getCurrentLocation(), location);\n    }\n\n    /**\n     * This method must be called from the main thread.\n     */\n    private static boolean isNestedApplication() {","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/HMCL-dev/HMCL/blob/24702dc5a0214034f4c27166d5fd30cad08cec19/HMCL/src/main/java/org/jackhuang/hmcl/upgrade/UpdateHandler.java#L248-L284","documentation":"getCurrentLocation resolves the path of the currently running HMCL JAR via JarUtils.thisJarPath(). If the JVM cannot determine the source JAR (null), HMCL cannot copy itself for updates or migration, so it throws this IOException.","triggerScenarios":"Calling updateFrom, self, or performMigration while the code is not running from a JAR file the launcher can locate — e.g. running from an exploded classes directory, from memory, or an exotic classloading setup where thisJarPath() returns null.","commonSituations":"Launching HMCL from an IDE without a JAR; running via a custom classloader or a shaded/native wrapper; some jpackage or module-path launches where the JAR path is not discoverable.","solutions":["Run HMCL from its distributed JAR (java -jar HMCL.jar)","Avoid launching from an exploded classpath/IDE when invoking update or restart features","Upgrade HMCL — newer JarUtils handle more launch layouts","If embedding HMCL, ensure the jar is a real file on disk, not an in-memory or nested-jar resource"],"exampleFix":"// before: IDE launch, no jar path\njava -cp build/classes org.jackhuang.hmcl.Main\n// after\njava -jar HMCL.jar","handlingStrategy":"type-guard","validationCode":"Path jar = JarUtils.thisJarPath();\nif (jar == null) {\n    LOG.warning(\"Not running from a jar; update unavailable\");\n    return;\n}","typeGuard":"boolean canSelfUpdate() {\n    return JarUtils.thisJarPath() != null;\n}","tryCatchPattern":"try {\n    Path loc = UpdateHandler.getCurrentLocation();\n} catch (IOException e) {\n    LOG.warning(\"Cannot determine jar location: \" + e.getMessage());\n}","preventionTips":["Always launch HMCL from a file-backed JAR (java -jar HMCL.jar)","Avoid invoking update/migration paths from IDE exploded classpaths","If embedding HMCL, ensure the jar exists on disk with a resolvable URL"],"tags":["jar","classpath","update"],"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"}