{"record":{"id":"0ace40781110bcc7","repo":"apache/flink","slug":"the-class-s-must-be-public","errorCode":null,"errorMessage":"The class %s must be public.","messagePattern":"The class (.+?) must be public\\.","errorType":"exception","errorClass":"ProgramInvocationException","httpStatus":null,"severity":"error","filePath":"flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java","lineNumber":331,"sourceCode":"            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        }\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())) {","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java#L313-L349","documentation":"Thrown by callMainMethod before attempting to look up the method, when the entry class's modifiers do not include public. A non-public class (package-private, protected, or private/nested) cannot be invoked as a main entry point even if it has a conforming main method.","triggerScenarios":"The entry point class is package-private or is a non-public nested class, but is referenced via --class or the manifest.","commonSituations":"Submitting a class that was never declared public (default access). Submitting an inner class (non-static or non-public) as the entry point. Code that 'worked in IDE' because the IDE bypassed access rules.","solutions":["Declare the entry class as 'public' (and top-level or public static nested).","If it must be nested, make the outer class public and the nested class 'public static'.","Rebuild the jar and resubmit, confirming the same class name resolves to the now-public class."],"exampleFix":"// before\nclass MyJob { // package-private\n    public static void main(String[] a) {}\n}\n\n// after\npublic class MyJob {\n    public static void main(String[] a) {}\n}","handlingStrategy":"validation","validationCode":"if (!Modifier.isPublic(entryClass.getModifiers())) {\n    throw new IllegalArgumentException(\n        \"Entry class \" + entryClass.getName() + \" must be public\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    PackagedProgram.newBuilder().setEntryPointClassName(cls).setJarFile(jar).build();\n} catch (ProgramInvocationException pie) {\n    if (pie.getMessage().contains(\"must be public\")) {\n        // tell user to make the class public\n    }\n    throw pie;\n}","preventionTips":["Always declare the entry class 'public'.","For nested entry classes, use 'public static' on both the outer and inner class.","Run a build-time check that the entry class is public."],"tags":["packaged-program","main-method","access-modifiers"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}