{"record":{"id":"89ea76409fdcb352","repo":"apache/hadoop","slug":"call-to-jni-createjavavm-failed-with-error-d","errorCode":null,"errorMessage":"Call to JNI_CreateJavaVM failed with error: %d\n","messagePattern":"Call to JNI_CreateJavaVM 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":744,"sourceCode":"          }\n        }\n\n        //Create the VM\n        vm_args.version = JNI_VERSION_1_2;\n        vm_args.options = options;\n        vm_args.nOptions = noArgs; \n        vm_args.ignoreUnrecognized = 1;\n\n        rv = JNI_CreateJavaVM(&vm, (void*)&env, &vm_args);\n\n        if (hadoopJvmArgs != NULL)  {\n          free(hadoopJvmArgs);\n        }\n        free(optHadoopClassPath);\n        free(options);\n\n        if (rv != 0) {\n            fprintf(stderr, \"Call to JNI_CreateJavaVM failed \"\n                    \"with error: %d\\n\", rv);\n            return NULL;\n        }\n\n        // We use findClassAndInvokeMethod here because the jclasses in\n        // jclasses.h have not loaded yet\n        jthr = findClassAndInvokeMethod(env, NULL, STATIC, NULL, HADOOP_FS,\n                \"loadFileSystems\", \"()V\");\n        if (jthr) {\n            printExceptionAndFree(env, jthr, PRINT_EXC_ALL,\n                    \"FileSystem: loadFileSystems failed\");\n            return NULL;\n        }\n    } else {\n        //Attach this thread to the VM\n        vm = vmBuf[0];\n        rv = (*vm)->AttachCurrentThread(vm, (void*)&env, 0);\n        if (rv != 0) {","sourceCodeStart":726,"sourceCodeEnd":762,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c#L726-L762","documentation":"libhdfs could not create the embedded JVM: JNI_CreateJavaVM returned a non-zero JNI result (JNI_ERR=-1 generic/bad option, JNI_EVERSION=-3 JNI version mismatch, JNI_ENOMEM=-4 heap not allocatable, JNI_EEXIST=-5 a VM already exists in-process with different options). libhdfs frees the option buffers and getGlobalJNIEnv returns NULL, so the triggering HDFS call fails. The numeric code in the message is the primary diagnostic.","triggerScenarios":"First libhdfs call with no prior JVM, where the JVM rejects the assembled options: malformed or obsolete LIBHDFS_OPTS flags; libjvm.so word-size or version mismatch with the libhdfs build; -Xmx in LIBHDFS_OPTS exceeding available memory (JNI_ENOMEM); another native component already created a JVM with incompatible options (JNI_EEXIST).","commonSituations":"JDK upgrades leaving dead flags in LIBHDFS_OPTS (e.g. -XX:MaxPermSize on JDK8+); memory-capped containers requesting big heaps; mixing JVM versions via LD_LIBRARY_PATH; embedding libhdfs in a process that already hosts a JVM.","solutions":["Decode the number: -1 bad option/unknown, -3 version mismatch, -4 out of memory, -5 VM already exists","Inspect LIBHDFS_OPTS and remove obsolete flags (drop -XX:MaxPermSize on JDK8+), then retry","Verify the libjvm.so on LD_LIBRARY_PATH matches the JVM version and word size libhdfs was built against (ldd on your binary)","For -4, lower -Xmx or raise the container/cgroup memory limit","For -5, align the existing VM's options (classpath and heap) with what libhdfs needs, since a second VM cannot be created in one process"],"exampleFix":"# before\nexport LIBHDFS_OPTS=\"-Xmx8g -XX:MaxPermSize=512m\"\n# Call to JNI_CreateJavaVM failed with error: -4\n\n# after (JDK8+, small container)\nexport LIBHDFS_OPTS=\"-Xmx1g\"","handlingStrategy":"validation","validationCode":"/* Smoke-test the embedded JVM at startup with conservative options */\nsetenv(\"LIBHDFS_OPTS\", \"-Xmx512m\", 0 /* do not override user */);\nhdfsFS fs = hdfsConnect(\"default\", 0);\nif (!fs) return EXIT_FAILURE; /* stderr carries the JNI error code */","typeGuard":null,"tryCatchPattern":"hdfsBuilder *b = hdfsNewBuilder();\nhdfsBuilderSetNameNode(b, \"default\");\nhdfsFS fs = hdfsBuilderConnect(b);\nif (!fs) {\n    /* the JNI_CreateJavaVM code is on stderr; capture it during bring-up */\n    fprintf(stderr, \"JVM bootstrap failed, errno=%d\\n\", errno);\n    exit(EXIT_FAILURE); /* do not retry: a half-created VM poisons the process */\n}","preventionTips":["Smoke-test hdfsConnect at process start and fail fast rather than discovering JVM failure mid-job","Keep LIBHDFS_OPTS minimal and aligned with the runtime JDK version","Verify the runtime libjvm (LD_LIBRARY_PATH/JAVA_HOME) matches the build-time JVM arch"],"tags":["libhdfs","jni","jvm","libhdfs-opts","jvm-options"],"backgroundTag":"jvm-creation-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}