{"record":{"id":"edb3eee7dfb1996e","repo":"openjdk/jdk","slug":"agent-error-badjar","errorCode":"AGENT_ERROR_BADJAR","errorMessage":"Error opening zip file or JAR manifest missing: %s\\n","messagePattern":"Error opening zip file or JAR manifest missing: (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/java.instrument/share/native/libinstrument/InvocationAdapter.c","lineNumber":342,"sourceCode":"    if (parseArgumentTail(args, &jarfile, &options) != 0) {\n        return JNI_ENOMEM;\n    }\n\n    jboolean print_warning = JVM_PrintWarningAtDynamicAgentLoad();\n    initerror = createNewJPLISAgent(vm, &agent, jarfile, print_warning);\n    if ( initerror == JPLIS_INIT_ERROR_NONE ) {\n        int             oldLen, newLen;\n        jarAttribute*   attributes;\n        char *          agentClass;\n        char *          bootClassPath;\n        jboolean        success;\n\n        /*\n         * Open the JAR file and parse the manifest\n         */\n        attributes = readAttributes( jarfile );\n        if (attributes == NULL) {\n            fprintf(stderr, \"Error opening zip file or JAR manifest missing: %s\\n\", jarfile);\n            free(jarfile);\n            if (options != NULL) free(options);\n            return AGENT_ERROR_BADJAR;\n        }\n\n        agentClass = getAttribute(attributes, \"Agent-Class\");\n        if (agentClass == NULL) {\n            fprintf(stderr, \"Failed to find Agent-Class manifest attribute from %s\\n\",\n                jarfile);\n            free(jarfile);\n            if (options != NULL) free(options);\n            freeAttributes(attributes);\n            return AGENT_ERROR_BADJAR;\n        }\n\n        /*\n         * Add the jarfile to the system class path\n         */","sourceCodeStart":324,"sourceCodeEnd":360,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/java.instrument/share/native/libinstrument/InvocationAdapter.c#L324-L360","documentation":"Thrown on the attach path (Agent_OnAttach, error code AGENT_ERROR_BADJAR = 100): the native code could not open the given JAR as a zip or could not find/parse META-INF/MANIFEST.MF inside it, so readAttributes returned NULL. The attach fails and the attach API raises AgentInitializationException with return code 100.","triggerScenarios":"VirtualMachine.loadAgent called with a path that is not a zip/jar (corrupt download, truncated file, plain directory), a jar built without a manifest, or a file unreadable due to permissions.","commonSituations":"APM/profiling tools (JMC, async-profiler wrappers, APM agents) attaching to a jar corrupted in transfer; agent jar generated by a pipeline step that skipped the manifest; typo'd or relative path resolved against the wrong working directory.","solutions":["Verify the file is a valid zip: unzip -t agent.jar (or jar tf agent.jar)","Confirm META-INF/MANIFEST.MF exists in the jar root and is parseable","Check file permissions/reads on the target JVM's working user","Rebuild or re-download the agent jar and re-attach"],"exampleFix":"# before: corrupted jar silently fails to attach\nvm.loadAgent(\"/tmp/agent.jar\");\n# after: validate before attaching\ntry (ZipFile z = new ZipFile(\"/tmp/agent.jar\")) {\n    if (z.getEntry(\"META-INF/MANIFEST.MF\") == null) throw new IllegalStateException(\"manifest missing\");\n}\nvm.loadAgent(\"/tmp/agent.jar\");","handlingStrategy":"validation","validationCode":"// before vm.loadAgent(path): confirm it is a readable zip with a manifest\nPath p = Path.of(agentPath);\nif (!Files.isRegularFile(p) || !Files.isReadable(p)) throw new IllegalArgumentException(\"agent jar missing/unreadable\");\ntry (ZipFile z = new ZipFile(p.toFile())) {\n    if (z.getEntry(\"META-INF/MANIFEST.MF\") == null) throw new IllegalArgumentException(\"manifest missing\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    vm.loadAgent(agentPath, options);\n} catch (AgentInitializationException e) {\n    if (e.returnValue() == 100) { /* BADJAR: re-fetch/rebuild jar, log and alert */ }\n}","preventionTips":["Checksum-verify agent jars (sha256) after download before attaching","Store agents in a stable directory owned by the JVM user"],"tags":["java-instrument","attach-api","jar","manifest","agent-error-badjar"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}