{"record":{"id":"ac9577578f668cfd","repo":"openjdk/jdk","slug":"java-lang-instrument-javaagent-cannot-create-nat","errorCode":null,"errorMessage":"java.lang.instrument/-javaagent: cannot create native agent.\\n","messagePattern":"java\\.lang\\.instrument/-javaagent: cannot create native agent\\.\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/java.instrument/share/native/libinstrument/InvocationAdapter.c","lineNumber":269,"sourceCode":"        /*\n         * Clean-up\n         */\n        freeAttributes(attributes);\n        free(premainClass);\n    }\n\n    if (initerror != JPLIS_INIT_ERROR_NONE) {\n        free(jarfile);\n    }\n    if (options != NULL) free(options);\n\n    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    }","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/openjdk/jdk/blob/88dfb74bbeefcf2b0aa11835183bcd949998fc8f/src/java.instrument/share/native/libinstrument/InvocationAdapter.c#L251-L287","documentation":"createNewJPLISAgent() returned JPLIS_INIT_ERROR_CANNOT_CREATE_NATIVE_AGENT — the native JPLISAgent structure (agent state, JNI environment bookkeeping, transform callbacks) could not be allocated/initialized. The launcher maps this enum to JNI_ERR and prints this line. It is the 'cannot even build the native agent object' failure, before any Java agent class is loaded.","triggerScenarios":"Internal allocation of the JPLISAgent or its dependent structures failing (OOM at startup), or environment/JNI state being invalid when -javaagent processing runs (unusual VM configurations, agents loaded in nested/foreign launchers that do not provide a proper JNIEnv). The switch in DEF_Agent_OnLoad maps this specific enum constant.","commonSituations":"Memory-exhausted hosts/containers at JVM start; custom launchers (embedded JVM via JNI_CreateJavaVM) that pass -javaagent options without a fully initialized VM; malformed embedding that violates the JNI invocation contract. Rare in standard 'java' launcher usage.","solutions":["Free memory / raise container limits and retry the JVM start","If embedding the JVM, ensure you pass agent options via JavaVMInitOptions properly and the VM is fully created before agent hooks run","Test with the stock 'java' launcher to isolate custom-launcher issues","Update the JDK — initialization paths in libinstrument have seen fixes across releases"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure adequate memory before launching with -javaagent","Embedders: create the VM via JNI_CreateJavaVM with proper options before agent hooks run","Test the exact agent+JDK combination in CI"],"tags":["javaagent","instrumentation","jvm-startup","native","initialization"],"backgroundTag":null,"analyzedSha":"88dfb74bbeefcf2b0aa11835183bcd949998fc8f","analyzedAt":"2026-08-14T11:45:09.665Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}