{"record":{"id":"de1f718bce681a2b","repo":"openjdk/jdk","slug":"javaagent-premain-class-value-is-too-big-n","errorCode":null,"errorMessage":"-javaagent: Premain-Class value is too big\\n","messagePattern":"-javaagent: Premain-Class value is too big\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/java.instrument/share/native/libinstrument/InvocationAdapter.c","lineNumber":209,"sourceCode":"            freeAttributes(attributes);\n            return JNI_ERR;\n        }\n\n        /*\n         * The value of the Premain-Class attribute becomes the agent\n         * class name. The manifest is in UTF8 so need to convert to\n         * modified UTF8 (see JNI spec).\n         */\n        oldLen = (int)strlen(premainClass);\n        newLen = modifiedUtf8LengthOfUtf8(premainClass, oldLen);\n        /*\n         * According to JVMS class name is represented as CONSTANT_Utf8_info,\n         * so its length is u2 (i.e. must be <= 0xFFFF).\n         * Negative oldLen or newLen means we got signed integer overflow\n         * (modifiedUtf8LengthOfUtf8 returns negative value if oldLen is negative).\n         */\n        if (oldLen < 0 || newLen < 0 || newLen > 0xFFFF) {\n            fprintf(stderr, \"-javaagent: Premain-Class value is too big\\n\");\n            free(jarfile);\n            if (options != NULL) free(options);\n            freeAttributes(attributes);\n            return JNI_ERR;\n        }\n        if (newLen == oldLen) {\n            premainClass = strdup(premainClass);\n        } else {\n            char* str = (char*)malloc( newLen+1 );\n            if (str != NULL) {\n                convertUtf8ToModifiedUtf8(premainClass, oldLen, str, newLen);\n            }\n            premainClass = str;\n        }\n        if (premainClass == NULL) {\n            fprintf(stderr, \"-javaagent: memory allocation failed\\n\");\n            free(jarfile);\n            if (options != NULL) free(options);","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/java.instrument/share/native/libinstrument/InvocationAdapter.c#L191-L227","documentation":"The Premain-Class value read from the manifest is too long to be a class name in the JVM: its modified-UTF-8 encoding exceeds 0xFFFF bytes, the u2 limit of CONSTANT_Utf8_info (JVMS 4.4.7). The code also treats negative lengths (signed overflow on strlen/conversion) as failure. Startup aborts with JNI_ERR.","triggerScenarios":"A manifest whose Premain-Class attribute is 64KB+ — essentially always a corrupted or generated-wrong manifest (binary garbage folded into the attribute), not a real class name; or a hostile/pathological jar. Real class names never approach 65535 bytes.","commonSituations":"Build tools concatenating files into the manifest incorrectly; template substitution gone wrong putting whole license text into Premain-Class; manifest line-folding bugs merging sections; fuzzed jars. Practically never seen with a legitimately built agent.","solutions":["Print the manifest: 'unzip -p agent.jar META-INF/MANIFEST.MF' and look at what Premain-Class actually contains","Fix the generation step that injected the oversized/garbage value (check Maven/Gradle manifest templates and property expansion)","Set Premain-Class to the real, short FQCN of the agent class and rebuild","If the jar came from elsewhere, treat it as corrupt and rebuild from source"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// reject absurd Premain-Class values at build time\nString pc = mf.getMainAttributes().getValue(\"Premain-Class\");\nif (pc != null && pc.getBytes(StandardCharsets.UTF_8).length > 0xFFFF)\n    throw new IllegalStateException(\"Premain-Class too long — manifest generation bug\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Assert manifest attribute lengths in the build, not at JVM launch","Review manifest templates for bad substitution that can inject large blobs","Treat any 64KB+ class name as corruption"],"tags":["javaagent","instrumentation","manifest","utf8","jvm-startup"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}