apache/flink · error · RuntimeException
Could not look up the main(String[]) method from the class %
Error message
Could not look up the main(String[]) method from the class %s: %s
What it means
Thrown by the private hasMainMethod(Class) helper when entryClass.getMethod("main", String[].class) raises something other than NoSuchMethodException (which would return false) — i.e. a SecurityException or other reflective-access Throwable. This is the lookup-time guard, distinct from the later invocation-time checks in callMainMethod.
Source
Thrown at flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java:315
return getJobJarAndDependencies(
jarFileUrl, extractedTempLibraries, isPython(entryPointClassName));
}
/** Deletes all temporary files created for contained packaged libraries. */
private void deleteExtractedLibraries() {
deleteExtractedLibraries(this.extractedTempLibraries);
this.extractedTempLibraries.clear();
}
private static boolean hasMainMethod(Class<?> entryClass) {
Method mainMethod;
try {
mainMethod = entryClass.getMethod("main", String[].class);
} catch (NoSuchMethodException e) {
return false;
} catch (Throwable t) {
throw new RuntimeException(
"Could not look up the main(String[]) method from the class "
+ entryClass.getName()
+ ": "
+ t.getMessage(),
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.");
}View on GitHub (pinned to 2f3c205e92)
Solutions
- Check the appended ': <message>' for the underlying reflection error and address it (e.g. add the missing 'opens' / reflection permission).
- If a SecurityManager is active, grant ReflectPermission / suppressAccessChecks as needed for the user-code classloader.
- On Java 17+, add '--add-opens java.base/java.lang=ALL-UNNAMED' or open the user module to Flink if running modular code.
- Ensure the entry class loads cleanly (no static-initializer failures that surface as LinkageError during getMethod).
Defensive patterns
Strategy: validation
Validate before calling
// Verify reflective access works before submission
try {
entryClass.getMethod("main", String[].class);
} catch (SecurityException se) {
// adjust SecurityManager / --add-opens before proceeding
} Try / catch
try {
PackagedProgram.newBuilder().setJarFile(jar).setEntryPointClassName(cls).build();
} catch (ProgramInvocationException pie) {
if (pie.getMessage().startsWith("Could not look up the main")) {
// inspect pie.getCause() for SecurityException / LinkageError
}
throw pie;
} Prevention
- On Java 17+, add '--add-opens' for packages accessed reflectively.
- Avoid running Flink under an overly strict SecurityManager in dev.
- Ensure entry classes load cleanly (no failing static initializers).
When it happens
Trigger: A SecurityManager denies reflective access to the method, or the JVM throws an unexpected Throwable (e.g. a LinkageError surfacing through reflection) during getMethod on the entry class.
Common situations: Running Flink under a restrictive SecurityManager, or in a sandboxed/container environment that limits reflection. Module-system (JPMS) access denials on Java 17+ when the entry class is in a non-opened module.
Related errors
- The given program class does not have a main(String[]) metho
- The class %s must be public.
- The class %s has no main(String[]) method.
- The class %s declares a non-static main method.
- The class %s declares a non-public main method.
AI-assisted analysis of apache/flink@2f3c205e92 (2026-08-14).
Data as JSON: /api/errors/27a9dbc27752fe82.
Report an issue: GitHub.