{"record":{"id":"99370fb4c84933a4","repo":"apache/flink","slug":"could-not-close-the-jar-file-t-getmessage","errorCode":null,"errorMessage":"Could not close the JAR file: {t.getMessage()}","messagePattern":"Could not close the JAR file: (.+?)","errorType":"exception","errorClass":"ProgramInvocationException","httpStatus":null,"severity":"warning","filePath":"flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java","lineNumber":452,"sourceCode":"            }\n\n            // check for a main class\n            className = attributes.getValue(PackagedProgram.MANIFEST_ATTRIBUTE_MAIN_CLASS);\n            if (className != null) {\n                return className;\n            } else {\n                throw new ProgramInvocationException(\n                        \"Neither a '\"\n                                + MANIFEST_ATTRIBUTE_MAIN_CLASS\n                                + \"', nor a '\"\n                                + MANIFEST_ATTRIBUTE_ASSEMBLER_CLASS\n                                + \"' entry was found in the jar file.\");\n            }\n        } finally {\n            try {\n                jar.close();\n            } catch (Throwable t) {\n                throw new ProgramInvocationException(\n                        \"Could not close the JAR file: \" + t.getMessage(), t);\n            }\n        }\n    }\n\n    @Nullable\n    private static URL loadJarFile(File jar) throws ProgramInvocationException {\n        if (jar != null) {\n            URL jarFileUrl;\n\n            try {\n                jarFileUrl = jar.getAbsoluteFile().toURI().toURL();\n            } catch (MalformedURLException e1) {\n                throw new IllegalArgumentException(\"The jar file path is invalid.\");\n            }\n\n            checkJarFile(jarFileUrl);\n","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-clients/src/main/java/org/apache/flink/client/program/PackagedProgram.java#L434-L470","documentation":"Thrown by getEntryPointClassNameFromJar in the finally block when jar.close() raises a Throwable. The original operation (reading the manifest/attributes) may have succeeded, but this close error masks it because the finally rethrows. It indicates an I/O or resource problem with the jar file handle.","triggerScenarios":"jar.close() fails in the finally clause — typically an IOException from the underlying random-access file/channel, or a Throwable from a closed/invalidated handle (e.g. the file was deleted during read).","commonSituations":"The jar file is on a network/remote filesystem that disconnects during read; the jar is deleted/moved concurrently; the OS file-handle limit is exhausted; antivirus locking the file.","solutions":["Ensure the jar is on a stable, local filesystem during submission.","Increase the OS file-descriptor limit (ulimit -n) if handle exhaustion is suspected.","Disable/reconfigure antivirus that may lock jar files mid-read.","Note: if the manifest read succeeded before close failed, the useful result is lost in the rethrow — retry after fixing the file-handle issue."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Ensure the jar is on a stable local FS and readable before submission\nif (!jarFile.exists() || !jarFile.canRead()) {\n    throw new IllegalArgumentException(\"Jar inaccessible: \" + jarFile);\n}\n// Optionally copy the jar to a local temp dir to avoid remote-FS disconnects during read","typeGuard":null,"tryCatchPattern":"try {\n    PackagedProgram.newBuilder().setJarFile(jarFile).build();\n} catch (ProgramInvocationException pie) {\n    if (pie.getMessage().startsWith(\"Could not close the JAR file\")) {\n        // the manifest read may have succeeded; retry after fixing file-handle / FS issue\n    }\n    throw pie;\n}","preventionTips":["Submit jars from a local filesystem, not a network mount.","Raise the OS file-descriptor limit (ulimit -n) for the Flink process.","Ensure antivirus/tools do not lock jar files during read."],"tags":["packaged-program","jar","io","resource-cleanup","finally"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}