HMCL-dev/HMCL · error · IOException

Failed to find current HMCL location

Error message

Failed to find current HMCL location

What it means

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.

Solutions

  1. Launch HMCL via java -jar HMCL.jar so its location is resolvable
  2. Guard the restart call: check JarUtils.thisJarPath() != null before offering restart to the user
  3. If embedding, provide a real JAR file path and avoid reflective bootstrapping
  4. Update to a newer HMCL that may support your launch layout

Example fix

// before
if (userClickedRestart) Restarter.restartSelf();
// after
if (userClickedRestart && JarUtils.thisJarPath() != null) {
    Restarter.restartSelf();
} else {
    LOG.warning("Restart unavailable: cannot locate application jar");
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (JarUtils.thisJarPath() == null) {
    LOG.warning("Restart unavailable: application jar not located");
    return;
}
Restarter.restartSelf();

Type guard

boolean restartable() {
    return JarUtils.thisJarPath() != null;
}

Try / catch

try {
    Restarter.restartSelf();
} catch (IOException e) {
    LOG.warning("Restart failed: " + e.getMessage());
    // surface 'please restart manually' to the user
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of HMCL-dev/HMCL@24702dc5a0 (2026-09-10). Data as JSON: /api/errors/6034c67950c158f1. Report an issue: GitHub.

Appendix: source

Thrown at HMCL/src/main/java/org/jackhuang/hmcl/util/Restarter.java:37

import org.jackhuang.hmcl.upgrade.UpdateHandler;
import org.jackhuang.hmcl.util.io.JarUtils;

import java.io.IOException;
import java.nio.file.Path;

import static org.jackhuang.hmcl.util.logging.Logger.LOG;

/// @author Glavo
public final class Restarter {

    /// Restart the current application.
    public static void restartSelf() throws IOException {
        LOG.info("Restarting HMCL");

        Path thisJar = JarUtils.thisJarPath();
        if (thisJar == null) {
            throw new IOException("Failed to find current HMCL location");
        }

        UpdateHandler.startJava(thisJar);
    }

    private Restarter() {
    }
}

View on GitHub (pinned to 24702dc5a0)