quarkusio/quarkus · error · IllegalStateException

Unable to find main method on class '${originalMainClassName

Error message

Unable to find main method on class '${originalMainClassName}' while it was also not possible to traverse the class hierarchy

What it means

When no valid main method is found on the class itself, doApply walks up the superclass chain looking for one. If the superclass DotName cannot be resolved in the Jandex index (superClassInfo == null), resultFromSuper throws this IllegalStateException because traversal is impossible.

Source

Thrown at core/deployment/src/main/java/io/quarkus/deployment/steps/MainClassBuildStep.java:716

            }
            if (!result.isValid) {
                // this means there were private main methods that we ignored
                result = resultFromSuper(originalMainClassName, classVisitor, transformer, currentClassInfo);
            }

            return result;
        }

        private Result resultFromSuper(String originalMainClassName, ClassVisitor outputClassVisitor,
                ClassTransformer transformer, ClassInfo currentClassInfo) {
            DotName superName = currentClassInfo.superName();
            if (superName.equals(OBJECT)) {
                // no valid main method was found
                return Result.invalid();
            }
            ClassInfo superClassInfo = index.getClassByName(superName);
            if (superClassInfo == null) {
                throw new IllegalStateException("Unable to find main method on class '" + originalMainClassName
                        + "' while it was also not possible to traverse the class hierarchy");
            }

            // check if the superclass has any valid candidates
            return doApply(originalMainClassName, outputClassVisitor, transformer, superClassInfo);
        }

        private static String errorMessage(String originalMainClassName) {
            return "Unable to find a valid main method on class '" + originalMainClassName
                    + "'. See https://openjdk.org/jeps/445 for details of what constitutes a valid main method.";
        }

        private static MethodCreator createStandardMain(ClassTransformer transformer) {
            return transformer.addMethod("main", void.class, String[].class)
                    .setModifiers(Modifier.PUBLIC | Modifier.STATIC);
        }

        private static class Result {

View on GitHub (pinned to e1c734241f)

Solutions

  1. Define a concrete public static void main(String[] args) directly in your main class so hierarchy traversal isn't needed
  2. Ensure the jar containing the superclass is Jandex-indexed (add a jandex.idx or META-INF/jandex.idx, or depend on the library's quarkus-published variant)
  3. Check dependency versions — the superclass artifact may be missing/corrupt in the local repository
  4. Simplify the main class hierarchy (don't rely on inheriting main from an unindexed parent)

Example fix

// before
public class MyApp extends SomeUnindexedBase { } // main only in base
// after
public class MyApp extends SomeUnindexedBase {
    public static void main(String[] args) { SomeUnindexedBase.run(args); }
}
Defensive patterns

Strategy: validation

Validate before calling

Class<?> c = Main.class;
while (c != null && !c.equals(Object.class)) {
    for (Method m : c.getDeclaredMethods()) {
        if (m.getName().equals("main")
                && java.lang.reflect.Modifier.isStatic(m.getModifiers())
                && Arrays.equals(m.getParameterTypes(), new Class<?>[]{String[].class})) {
            return; // found in hierarchy
        }
    }
    c = c.getSuperclass();
}
throw new IllegalStateException("No main in hierarchy; declare one in your main class");

Try / catch

try {
    quarkusBuild();
} catch (IllegalStateException e) {
    if (e.getMessage() != null && e.getMessage().contains("not possible to traverse the class hierarchy")) {
        // index the superclass jar or declare main directly
    }
    throw e;
}

Prevention

When it happens

Trigger: In resultFromSuper (called from doApply): the candidate class has a non-Object superclass whose ClassInfo is absent from the application index — typically a superclass from an unindexed dependency.

Common situations: Main class extends a class from a third-party jar that isn't Jandex-indexed; a generated or dynamically added superclass unknown to the index; binary-incompatible dependency versions where the parent class can't be resolved.

Related errors


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/07661ff30e8ee67f. Report an issue: GitHub.