{"record":{"id":"4a74a7ce62aa29de","repo":"openjdk/jdk","slug":"javaagent-agent-class-not-specified-n","errorCode":null,"errorMessage":"-javaagent: agent class not specified.\\n","messagePattern":"-javaagent: agent class not specified\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/java.instrument/share/native/libinstrument/InvocationAdapter.c","lineNumber":281,"sourceCode":"    switch (initerror) {\n    case JPLIS_INIT_ERROR_NONE:\n      result = JNI_OK;\n      break;\n    case JPLIS_INIT_ERROR_CANNOT_CREATE_NATIVE_AGENT:\n      result = JNI_ERR;\n      fprintf(stderr, \"java.lang.instrument/-javaagent: cannot create native agent.\\n\");\n      break;\n    case JPLIS_INIT_ERROR_FAILURE:\n      result = JNI_ERR;\n      fprintf(stderr, \"java.lang.instrument/-javaagent: initialization of native agent failed.\\n\");\n      break;\n    case JPLIS_INIT_ERROR_ALLOCATION_FAILURE:\n      result = JNI_ERR;\n      fprintf(stderr, \"java.lang.instrument/-javaagent: allocation failure.\\n\");\n      break;\n    case JPLIS_INIT_ERROR_AGENT_CLASS_NOT_SPECIFIED:\n      result = JNI_ERR;\n      fprintf(stderr, \"-javaagent: agent class not specified.\\n\");\n      break;\n    default:\n      result = JNI_ERR;\n      fprintf(stderr, \"java.lang.instrument/-javaagent: unknown error\\n\");\n      break;\n    }\n    return result;\n}\n\n/*\n * Agent_OnAttach returns a jint. 0/JNI_OK indicates success and non-0\n * indicates an error. To allow the attach mechanism throw an\n * AgentInitializationException with a reasonable exception message we define\n * a few specific errors here.\n */\n#define AGENT_ERROR_BADJAR    ((jint)100)  /* Agent JAR not found or no Agent-Class attribute */\n#define AGENT_ERROR_NOTONCP   ((jint)101)  /* Unable to add JAR file to system class path */\n#define AGENT_ERROR_STARTFAIL ((jint)102)  /* No agentmain method or agentmain failed */","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/java.instrument/share/native/libinstrument/InvocationAdapter.c#L263-L299","documentation":"The instrument library could not determine which class to load as the agent: the JAR's manifest has no usable agent class attribute for the current path (Premain-Class at JVM launch, Agent-Class when attaching). JPLIS initialization returns JPLIS_INIT_ERROR_AGENT_CLASS_NOT_SPECIFIED and Agent_OnLoad returns JNI_ERR, failing JVM startup when given on the command line.","triggerScenarios":"Launching with -javaagent:some.jar whose META-INF/MANIFEST.MF lacks Premain-Class; attaching at runtime to a jar lacking Agent-Class; a manifest that exists but with a misspelled attribute name or one placed outside the main section.","commonSituations":"Hand-built agent JARs where the manifest was overwritten by the build tool; fat/uber JARs repackaged with a new manifest; shading plugins stripping manifest attributes; typo 'PreMain-Class' instead of 'Premain-Class'.","solutions":["Unzip the agent jar and inspect META-INF/MANIFEST.MF: unzip -p agent.jar META-INF/MANIFEST.MF","Add 'Premain-Class: com.example.Agent' for load-time agents (and 'Agent-Class: com.example.Agent' for attach-time) to the manifest main section","Configure the build to preserve/merge manifest attributes (e.g. maven-shade-plugin ManifestResourceTransformer, Gradle jar manifest block)","Verify the agent class has a valid public static premain(String, Instrumentation) (or agentmain) method"],"exampleFix":"// before: no manifest attributes\njar cf agent.jar -C classes .\n// after\nprintf 'Premain-Class: com.example.Agent\\nCan-Redefine-Classes: true\\n' > mf.txt\njar cfm agent.jar mf.txt -C classes .","handlingStrategy":"validation","validationCode":"// validate an agent jar before putting it on the command line\ntry (JarFile jf = new JarFile(\"agent.jar\")) {\n    Manifest mf = jf.getManifest();\n    if (mf == null || mf.getMainAttributes().getValue(\"Premain-Class\") == null)\n        throw new IllegalArgumentException(\"agent.jar lacks Premain-Class\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add a build-time check that fails the build if the agent jar manifest lacks Premain-Class","Use ManifestResourceTransformer (shade) / jar manifest blocks instead of hand-written manifests","Smoke-launch java -javaagent:agent.jar -version in CI to catch bad manifests early"],"tags":["java-instrument","manifest","javaagent","configuration","jvm-startup"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}