openjdk/jdk · critical
Failed to find Premain-Class manifest attribute in %s\n
Error message
Failed to find Premain-Class manifest attribute in %s\n
What it means
The agent jar opened fine and its manifest attributes were read, but the required 'Premain-Class' attribute is absent from META-INF/MANIFEST.MF. The java.lang.instrument contract requires every -javaagent jar to name its premain entry point this way. Without it the launcher prints this error, frees resources, and returns JNI_ERR, refusing to start.
Source
Thrown at src/java.instrument/share/native/libinstrument/InvocationAdapter.c:187
* Agent_OnLoad is specified to provide the agent options
* argument tail in modified UTF8. However for 1.5.0 this is
* actually in the platform encoding - see 5049313.
*
* Open zip/jar file and parse archive. If can't be opened or
* not a zip file return error. Also if Premain-Class attribute
* isn't present we return an error.
*/
attributes = readAttributes(jarfile);
if (attributes == NULL) {
fprintf(stderr, "Error opening zip file or JAR manifest missing : %s\n", jarfile);
free(jarfile);
if (options != NULL) free(options);
return JNI_ERR;
}
premainClass = getAttribute(attributes, "Premain-Class");
if (premainClass == NULL) {
fprintf(stderr, "Failed to find Premain-Class manifest attribute in %s\n",
jarfile);
free(jarfile);
if (options != NULL) free(options);
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 overflowView on GitHub (pinned to 88dfb74bbe)
Solutions
- Add 'Premain-Class: your.Agent' to the manifest and ensure the attribute name is spelled exactly (case-sensitive, colon+space)
- Configure the build: Maven jar plugin <manifestEntries><Premain-Class>...</Premain-Class></manifestEntries> or Gradle jar { manifest { attributes 'Premain-Class': 'your.Agent' } }
- If you intend runtime attach instead of -javaagent, use Agent-Class and attach via the Attach API; do not launch with -javaagent
- Inspect with 'unzip -p agent.jar META-INF/MANIFEST.MF' to confirm the attribute and correct section (must be in main section, before first blank line)
Example fix
// build.gradle — before
jar { manifest { attributes 'Main-Class': 'myapp.Main' } } // no Premain-Class
// after
jar {
manifest {
attributes 'Premain-Class': 'com.example.MyAgent',
'Can-Retransform-Classes': 'true'
}
} Defensive patterns
Strategy: validation
Validate before calling
// build-time assertion that Premain-Class exists
try (ZipFile z = new ZipFile("agent.jar")) {
Manifest mf = new Manifest(z.getInputStream(z.getEntry("META-INF/MANIFEST.MF")));
String pc = mf.getMainAttributes().getValue("Premain-Class");
if (pc == null || pc.isBlank()) throw new IllegalStateException("Premain-Class missing");
} Prevention
- Declare Premain-Class in the jar manifest attributes of the build (Maven manifestEntries / Gradle attributes)
- Attribute names are case-sensitive: exactly 'Premain-Class'
- For attach-only agents use Agent-Class and the Attach API, not -javaagent
When it happens
Trigger: Manifest exists (so error 134 passed) but lacks the line 'Premain-Class: com.example.AgentClass'. Typical when the manifest was generated by a build plugin default template, or hand-written with a typo ('Premain class', trailing spaces in the attribute name are significant — the spec requires exact 'Premain-Class:').
Common situations: Maven/Gradle builds where the manifest section is added to the wrong task or the attribute is inside a nested section; multi-line folding breaking the attribute; agents built by tutorials missing the attribute entirely; using Agent-Class (for attach) only, then launching with -javaagent which requires Premain-Class.
Related errors
- Error opening zip file or JAR manifest missing : %s\n
- -javaagent: Premain-Class value is too big\n
- -javaagent: memory allocation failure.\n
- -javaagent: memory allocation failed\n
- java.lang.instrument/-javaagent: cannot create native agent.
AI-assisted analysis of openjdk/jdk@88dfb74bbe (2026-08-14).
Data as JSON: /api/errors/8d2a9504025429bf.
Report an issue: GitHub.