apache/flink · error · ProgramInvocationException

The class %s has no main(String[]) method.

Error message

The class %s has no main(String[]) method.

What it means

Thrown by callMainMethod when entryClass.getMethod("main", String[].class) raises NoSuchMethodException. Note this is a separate check from the earlier hasMainMethod call: the constructor gates on hasMainMethod, but callMainMethod re-validates at invocation time, so this fires if the class lost its main method between construction and invocation, or callMainMethod is called on a different class than was validated.

Source

Thrown at flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java:338

                    t);
        }

        return Modifier.isStatic(mainMethod.getModifiers())
                && Modifier.isPublic(mainMethod.getModifiers());
    }

    private static void callMainMethod(Class<?> entryClass, String[] args)
            throws ProgramInvocationException {
        Method mainMethod;
        if (!Modifier.isPublic(entryClass.getModifiers())) {
            throw new ProgramInvocationException(
                    "The class " + entryClass.getName() + " must be public.");
        }

        try {
            mainMethod = entryClass.getMethod("main", String[].class);
        } catch (NoSuchMethodException e) {
            throw new ProgramInvocationException(
                    "The class " + entryClass.getName() + " has no main(String[]) method.");
        } catch (Throwable t) {
            throw new ProgramInvocationException(
                    "Could not look up the main(String[]) method from the class "
                            + entryClass.getName()
                            + ": "
                            + t.getMessage(),
                    t);
        }

        if (!Modifier.isStatic(mainMethod.getModifiers())) {
            throw new ProgramInvocationException(
                    "The class " + entryClass.getName() + " declares a non-static main method.");
        }
        if (!Modifier.isPublic(mainMethod.getModifiers())) {
            throw new ProgramInvocationException(
                    "The class " + entryClass.getName() + " declares a non-public main method.");
        }

View on GitHub (pinned to 2f3c205e92)

Solutions

  1. Ensure the entry class defines 'public static void main(String[])'.
  2. Verify the exact signature: parameter must be String[] (not String... or Object[]).
  3. Check that the classloader used at invocation matches the one at PackagedProgram construction.

Example fix

// before
public class MyJob {
    public static void main(String args) { ... } // wrong signature
}

// after
public class MyJob {
    public static void main(String[] args) throws Exception { ... }
}
Defensive patterns

Strategy: validation

Validate before calling

boolean hasMain;
try {
    Method m = entryClass.getMethod("main", String[].class);
    hasMain = Modifier.isPublic(m.getModifiers()) && Modifier.isStatic(m.getModifiers());
} catch (NoSuchMethodException e) {
    hasMain = false;
}
if (!hasMain) throw new IllegalArgumentException("Missing public static main(String[])");

Try / catch

try {
    packagedProgram.invokeInteractiveModeForExecution();
} catch (ProgramInvocationException pie) {
    if (pie.getMessage().contains("has no main(String[])")) {
        // fix signature / rebuild jar
    }
    throw pie;
}

Prevention

When it happens

Trigger: callMainMethod is invoked on a class whose getMethod("main", String[].class) returns no method. This is essentially the same condition as error 61 but reported at invoke time.

Common situations: A program class loaded at construction differs from the one used at invocation (e.g. multiple classloaders), or the main method was removed/renamed between build steps.

Related errors


AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14). Data as JSON: /api/errors/06c28262cdfca90e. Report an issue: GitHub.