{"record":{"id":"4513f9038b2214ba","repo":"apache/flink","slug":"the-class-s-declares-a-non-static-main-method","errorCode":null,"errorMessage":"The class %s declares a non-static main method.","messagePattern":"The class (.+?) declares a non-static main method\\.","errorType":"exception","errorClass":"ProgramInvocationException","httpStatus":null,"severity":"error","filePath":"flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java","lineNumber":350,"sourceCode":"                    \"The class \" + entryClass.getName() + \" must be public.\");\n        }\n\n        try {\n            mainMethod = entryClass.getMethod(\"main\", String[].class);\n        } catch (NoSuchMethodException e) {\n            throw new ProgramInvocationException(\n                    \"The class \" + entryClass.getName() + \" has no main(String[]) method.\");\n        } catch (Throwable t) {\n            throw new ProgramInvocationException(\n                    \"Could not look up the main(String[]) method from the class \"\n                            + entryClass.getName()\n                            + \": \"\n                            + t.getMessage(),\n                    t);\n        }\n\n        if (!Modifier.isStatic(mainMethod.getModifiers())) {\n            throw new ProgramInvocationException(\n                    \"The class \" + entryClass.getName() + \" declares a non-static main method.\");\n        }\n        if (!Modifier.isPublic(mainMethod.getModifiers())) {\n            throw new ProgramInvocationException(\n                    \"The class \" + entryClass.getName() + \" declares a non-public main method.\");\n        }\n\n        try {\n            mainMethod.invoke(null, (Object) args);\n        } catch (IllegalArgumentException e) {\n            throw new ProgramInvocationException(\n                    \"Could not invoke the main method, arguments are not matching.\", e);\n        } catch (IllegalAccessException e) {\n            throw new ProgramInvocationException(\n                    \"Access to the main method was denied: \" + e.getMessage(), e);\n        } catch (InvocationTargetException e) {\n            Throwable exceptionInMethod = e.getTargetException();\n            if (exceptionInMethod instanceof Error) {","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java#L332-L368","documentation":"Thrown by callMainMethod after the main method is found, when Modifier.isStatic returns false. A non-static main method cannot be invoked without an instance and is not a valid JVM entry point.","triggerScenarios":"The class declares a main(String[]) method but omits the 'static' keyword.","commonSituations":"Copy-paste of a method body into a new class without the static modifier; refactoring that removed 'static'; submitting a class meant to be instantiated rather than run directly.","solutions":["Add the 'static' modifier to the main method: 'public static void main(String[] args)'.","Rebuild and resubmit the jar."],"exampleFix":"// before\npublic class MyJob {\n    public void main(String[] args) { ... } // missing static\n}\n\n// after\npublic class MyJob {\n    public static void main(String[] args) throws Exception { ... }\n}","handlingStrategy":"validation","validationCode":"try {\n    Method m = entryClass.getMethod(\"main\", String[].class);\n    if (!Modifier.isStatic(m.getModifiers())) {\n        throw new IllegalArgumentException(\"main must be static\");\n    }\n} catch (NoSuchMethodException e) {\n    throw new IllegalArgumentException(\"no main(String[])\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    packagedProgram.invokeInteractiveModeForExecution();\n} catch (ProgramInvocationException pie) {\n    if (pie.getMessage().contains(\"non-static main\")) {\n        // add 'static' to main and rebuild\n    }\n    throw pie;\n}","preventionTips":["Always write 'public static void main(String[] args)'.","Use IDE templates for the main method to avoid missing modifiers."],"tags":["packaged-program","main-method","static-modifier"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}