{"record":{"id":"27a9dbc27752fe82","repo":"apache/flink","slug":"could-not-look-up-the-main-string-method-from-t","errorCode":null,"errorMessage":"Could not look up the main(String[]) method from the class %s: %s","messagePattern":"Could not look up the main\\(String\\[\\]\\) method from the class (.+?): (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java","lineNumber":315,"sourceCode":"\n        return getJobJarAndDependencies(\n                jarFileUrl, extractedTempLibraries, isPython(entryPointClassName));\n    }\n\n    /** Deletes all temporary files created for contained packaged libraries. */\n    private void deleteExtractedLibraries() {\n        deleteExtractedLibraries(this.extractedTempLibraries);\n        this.extractedTempLibraries.clear();\n    }\n\n    private static boolean hasMainMethod(Class<?> entryClass) {\n        Method mainMethod;\n        try {\n            mainMethod = entryClass.getMethod(\"main\", String[].class);\n        } catch (NoSuchMethodException e) {\n            return false;\n        } catch (Throwable t) {\n            throw new RuntimeException(\n                    \"Could not look up the main(String[]) method from the class \"\n                            + entryClass.getName()\n                            + \": \"\n                            + t.getMessage(),\n                    t);\n        }\n\n        return Modifier.isStatic(mainMethod.getModifiers())\n                && Modifier.isPublic(mainMethod.getModifiers());\n    }\n\n    private static void callMainMethod(Class<?> entryClass, String[] args)\n            throws ProgramInvocationException {\n        Method mainMethod;\n        if (!Modifier.isPublic(entryClass.getModifiers())) {\n            throw new ProgramInvocationException(\n                    \"The class \" + entryClass.getName() + \" must be public.\");\n        }","sourceCodeStart":297,"sourceCodeEnd":333,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java#L297-L333","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify reflective access works before submission\ntry {\n    entryClass.getMethod(\"main\", String[].class);\n} catch (SecurityException se) {\n    // adjust SecurityManager / --add-opens before proceeding\n}","typeGuard":null,"tryCatchPattern":"try {\n    PackagedProgram.newBuilder().setJarFile(jar).setEntryPointClassName(cls).build();\n} catch (ProgramInvocationException pie) {\n    if (pie.getMessage().startsWith(\"Could not look up the main\")) {\n        // inspect pie.getCause() for SecurityException / LinkageError\n    }\n    throw pie;\n}","preventionTips":["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)."],"tags":["packaged-program","reflection","security","main-method"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}