{"record":{"id":"28075496153cc3c4","repo":"apache/hadoop","slug":"jni-getcreatedjavavms-failed-with-error-d","errorCode":null,"errorMessage":"JNI_GetCreatedJavaVMs failed with error: %d\n","messagePattern":"JNI_GetCreatedJavaVMs failed with error: (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c","lineNumber":677,"sourceCode":"    JNIEnv *env;\n    jint rv = 0; \n    jint noVMs = 0;\n    jthrowable jthr;\n    char *hadoopClassPath;\n    const char *hadoopClassPathVMArg = \"-Djava.class.path=\";\n    size_t optHadoopClassPathLen;\n    char *optHadoopClassPath;\n    int noArgs = 1;\n    char *hadoopJvmArgs;\n    char jvmArgDelims[] = \" \";\n    char *str, *token, *savePtr;\n    JavaVMInitArgs vm_args;\n    JavaVM *vm;\n    JavaVMOption *options;\n\n    rv = JNI_GetCreatedJavaVMs(&(vmBuf[0]), VM_BUF_LENGTH, &noVMs);\n    if (rv != 0) {\n        fprintf(stderr, \"JNI_GetCreatedJavaVMs failed with error: %d\\n\", rv);\n        return NULL;\n    }\n\n    if (noVMs == 0) {\n        //Get the environment variables for initializing the JVM\n        hadoopClassPath = getClassPath();\n        if (hadoopClassPath == NULL) {\n            fprintf(stderr, \"Environment variable CLASSPATH not set!\\n\");\n            return NULL;\n        } \n        optHadoopClassPathLen = strlen(hadoopClassPath) + \n          strlen(hadoopClassPathVMArg) + 1;\n        optHadoopClassPath = malloc(sizeof(char)*optHadoopClassPathLen);\n        snprintf(optHadoopClassPath, optHadoopClassPathLen,\n                \"%s%s\", hadoopClassPathVMArg, hadoopClassPath);\n\n        free(hadoopClassPath);\n","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c#L659-L695","documentation":"The first step of JVM bootstrap in getGlobalJNIEnv is JNI_GetCreatedJavaVMs to check whether a VM already exists in the process. A non-zero return code (JNI_ERR, or a version-incompatibility error from the detected VM) prints this message and makes getJNIEnv return NULL, after which every libhdfs call fails with EINTERNAL.","triggerScenarios":"A broken or architecture-mismatched libjvm.so on LD_LIBRARY_PATH; an existing JVM of an incompatible version already created in the process by an embedding framework; a corrupted JDK installation.","commonSituations":"Mixed Java versions between an embedding application and the Hadoop installation; LD_LIBRARY_PATH pointing at a partial JDK copy; 32-bit vs 64-bit library mismatch.","solutions":["Verify JAVA_HOME/LD_LIBRARY_PATH point at a complete JDK matching the process architecture and version","Identify which JVM an embedding framework already created in-process and align its version with Hadoop's expectation","Validate the JDK with a trivial JNI program against the same environment to isolate libhdfs"],"exampleFix":"# before\nexport LD_LIBRARY_PATH=/opt/partial-jdk/lib/server:/opt/hadoop/lib/native   # broken JDK copy\n\n# after\nexport JAVA_HOME=/usr/lib/jvm/java-8-openjdk\nexport LD_LIBRARY_PATH=$JAVA_HOME/lib/server:/opt/hadoop/lib/native","handlingStrategy":"validation","validationCode":"/* validate the JVM environment before the first libhdfs call */\nstatic int jvm_env_ok(void) {\n    const char *jh = getenv(\"JAVA_HOME\");\n    char path[PATH_MAX];\n    if (!jh) return 0;\n    snprintf(path, sizeof(path), \"%s/lib/server/libjvm.so\", jh);\n    return access(path, R_OK) == 0;   /* complete, matching-arch JDK required */\n}","typeGuard":null,"tryCatchPattern":"if (hdfsConnect(uri, user) == NULL && errno == EINTERNAL) {\n    /* check stderr for 'JNI_GetCreatedJavaVMs failed': fix JAVA_HOME/LD_LIBRARY_PATH,\n       do not retry with the same broken environment */\n}","preventionTips":["Pin JAVA_HOME and LD_LIBRARY_PATH to one complete JDK in service env scripts","Align the JDK version/architecture of embedding frameworks with the Hadoop installation","Validate the JDK with a trivial JNI program when in doubt"],"tags":["hdfs","libhdfs","jni","jvm","initialization"],"backgroundTag":"jvm-initialization-failure","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}