HMCL-dev/HMCL · error · IOException

Failed to find current HMCL location

Error message

Failed to find current HMCL location

What it means

JavaInfo.fromExecutable runs the candidate java executable with the HMCL jar on the classpath to introspect it, so it needs the path of the currently running HMCL jar. When JarUtils.thisJarPath() returns null (HMCL is not running from a jar), an IOException is thrown because the introspection cannot proceed.

Solutions

  1. Run HMCL from its packaged jar rather than an exploded directory or IDE classpath
  2. Rebuild/repackage the jar so it exists at a resolvable filesystem location
  3. In development, substitute a stub/known JavaInfo instead of calling fromExecutable
  4. Check JarUtils.thisJarPath() != null before calling and handle the null case gracefully

Example fix

// before
JavaInfo info = JavaInfo.fromExecutable(executable);
// after
Path thisJar = JarUtils.thisJarPath();
if (thisJar == null) {
    JavaInfo info = queryJavaInfoDirectly(executable); // e.g. parse "java -version" output
} else {
    JavaInfo info = JavaInfo.fromExecutable(executable);
}
Defensive patterns

Strategy: type-guard

Validate before calling

if (JarUtils.thisJarPath() == null) {
    throw new IllegalStateException("HMCL must run from a packaged jar for Java introspection");
}

Type guard

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

Try / catch

try {
    JavaInfo info = JavaInfo.fromExecutable(executable);
} catch (IOException e) {
    LOG.warning("Cannot introspect java: HMCL jar location unknown (running from IDE?)", e);
    return null;
}

Prevention

When it happens

Trigger: Calling JavaInfo.fromExecutable(executable) while HMCL is running from an exploded class directory, an IDE, or any environment where JarUtils.thisJarPath() cannot determine the current jar location.

Common situations: Running HMCL from an IDE (development mode) instead of the packaged jar; running via an unpacked build; exotic classloaders where the jar path is indeterminable; running from jshell or a custom launcher.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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

Appendix: source

Thrown at HMCL/src/main/java/org/jackhuang/hmcl/java/JavaInfoUtils.java:47

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

/**
 * @author Glavo
 * @see <a href="https://github.com/Glavo/java-info">Glavo/java-info</a>
 */
public final class JavaInfoUtils {

    private JavaInfoUtils() {
    }

    public static @NotNull JavaInfo fromExecutable(Path executable) throws IOException {
        assert executable.isAbsolute();

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

        try {
            Result result = JsonUtils.GSON.fromJson(SystemUtils.run(
                    executable.toString(),
                    "-classpath",
                    thisPath.toString(),
                    org.glavo.info.Main.class.getName()
            ), Result.class);

            if (result == null) {
                throw new IOException("Failed to get Java info from " + executable);
            }

            if (result.javaVersion == null) {
                throw new IOException("Failed to get Java version from " + executable);
            }

View on GitHub (pinned to 24702dc5a0)