apache/flink · error · ProgramInvocationException
Could not invoke the main method, arguments are not matching
Error message
Could not invoke the main method, arguments are not matching.
What it means
Thrown by callMainMethod when Method.invoke raises IllegalArgumentException. Because the resolved method is main(String[]) and the argument passed is (Object) args (a String[]), an IllegalArgumentException here is unusual and typically indicates a JVM-level arity/signature mismatch rather than a user-correctable condition.
Source
Thrown at flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java:361
+ 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.");
}
try {
mainMethod.invoke(null, (Object) args);
} catch (IllegalArgumentException e) {
throw new ProgramInvocationException(
"Could not invoke the main method, arguments are not matching.", e);
} catch (IllegalAccessException e) {
throw new ProgramInvocationException(
"Access to the main method was denied: " + e.getMessage(), e);
} catch (InvocationTargetException e) {
Throwable exceptionInMethod = e.getTargetException();
if (exceptionInMethod instanceof Error) {
throw (Error) exceptionInMethod;
} else if (exceptionInMethod instanceof ProgramParametrizationException) {
throw (ProgramParametrizationException) exceptionInMethod;
} else if (exceptionInMethod instanceof ProgramInvocationException) {
throw (ProgramInvocationException) exceptionInMethod;
} else {
throw new ProgramInvocationException(
"The main method caused an error: " + exceptionInMethod.getMessage(),
exceptionInMethod);
}
} catch (Throwable t) {View on GitHub (pinned to 2f3c205e92)
Solutions
- Inspect the attached IllegalArgumentException cause for the actual argument-type mismatch.
- Confirm there is exactly one main(String[]) method (no synthetic/bridge duplicates) via javap on the class.
- Remove bytecode-rewriting agents on the client JVM and resubmit.
- If using Kotlin/Scala, ensure the compiled main is a true Java static main(String[]).
Defensive patterns
Strategy: try-catch
Validate before calling
// Inspect the method shape via reflection / javap before submitting
Method m = entryClass.getMethod("main", String[].class);
if (m.isBridge() || m.isSynthetic()) {
log.warn("main method is synthetic/bridge: {}", m);
} Try / catch
try {
packagedProgram.invokeInteractiveModeForExecution();
} catch (ProgramInvocationException pie) {
if (pie.getMessage().contains("arguments are not matching")) {
// run javap -v on the entry class to inspect main's true signature
}
throw pie;
} Prevention
- Avoid bytecode-rewriting agents that change main's signature.
- For Kotlin/Scala, ensure a genuine Java static main(String[]) is emitted.
- Run javap on the compiled class to confirm main(String[]) is the only overload.
When it happens
Trigger: Method.invoke(null, (Object) args) where args is a String[] but the JVM rejects the argument wrapping. Rare; can occur with synthetic/bridge main methods or bytecode-rewritten classes.
Common situations: The submitted class has been instrumented (agent, Lombok, Kotlin compiler quirks) producing a non-standard main signature; classpath shadowing with a different but compatible-named method.
Related errors
- Could not look up the main(String[]) method from the class %
- The class %s has no main(String[]) method.
- Access to the main method was denied: {e.getMessage()}
- The main method caused an error: {exceptionInMethod.getMessa
- An error occurred while invoking the program's main method:
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/3d7f669a7adf51fd.
Report an issue: GitHub.