openjdk/jdk · critical

-javaagent: Premain-Class value is too big\n

Error message

-javaagent: Premain-Class value is too big\n

What it means

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.

Source

Thrown at src/java.instrument/share/native/libinstrument/InvocationAdapter.c:209

            freeAttributes(attributes);
            return JNI_ERR;
        }

        /*
         * The value of the Premain-Class attribute becomes the agent
         * class name. The manifest is in UTF8 so need to convert to
         * modified UTF8 (see JNI spec).
         */
        oldLen = (int)strlen(premainClass);
        newLen = modifiedUtf8LengthOfUtf8(premainClass, oldLen);
        /*
         * According to JVMS class name is represented as CONSTANT_Utf8_info,
         * so its length is u2 (i.e. must be <= 0xFFFF).
         * Negative oldLen or newLen means we got signed integer overflow
         * (modifiedUtf8LengthOfUtf8 returns negative value if oldLen is negative).
         */
        if (oldLen < 0 || newLen < 0 || newLen > 0xFFFF) {
            fprintf(stderr, "-javaagent: Premain-Class value is too big\n");
            free(jarfile);
            if (options != NULL) free(options);
            freeAttributes(attributes);
            return JNI_ERR;
        }
        if (newLen == oldLen) {
            premainClass = strdup(premainClass);
        } else {
            char* str = (char*)malloc( newLen+1 );
            if (str != NULL) {
                convertUtf8ToModifiedUtf8(premainClass, oldLen, str, newLen);
            }
            premainClass = str;
        }
        if (premainClass == NULL) {
            fprintf(stderr, "-javaagent: memory allocation failed\n");
            free(jarfile);
            if (options != NULL) free(options);

View on GitHub (pinned to 88dfb74bbe)

Solutions

  1. Print the manifest: 'unzip -p agent.jar META-INF/MANIFEST.MF' and look at what Premain-Class actually contains
  2. Fix the generation step that injected the oversized/garbage value (check Maven/Gradle manifest templates and property expansion)
  3. Set Premain-Class to the real, short FQCN of the agent class and rebuild
  4. If the jar came from elsewhere, treat it as corrupt and rebuild from source
Defensive patterns

Strategy: validation

Validate before calling

// reject absurd Premain-Class values at build time
String pc = mf.getMainAttributes().getValue("Premain-Class");
if (pc != null && pc.getBytes(StandardCharsets.UTF_8).length > 0xFFFF)
    throw new IllegalStateException("Premain-Class too long — manifest generation bug");

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of openjdk/jdk@88dfb74bbe (2026-08-14). Data as JSON: /api/errors/de1f718bce681a2b. Report an issue: GitHub.