apache/hadoop · critical
Call to JNI_CreateJavaVM failed with error: %d
Error message
Call to JNI_CreateJavaVM failed with error: %d
What it means
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.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c:744
}
}
//Create the VM
vm_args.version = JNI_VERSION_1_2;
vm_args.options = options;
vm_args.nOptions = noArgs;
vm_args.ignoreUnrecognized = 1;
rv = JNI_CreateJavaVM(&vm, (void*)&env, &vm_args);
if (hadoopJvmArgs != NULL) {
free(hadoopJvmArgs);
}
free(optHadoopClassPath);
free(options);
if (rv != 0) {
fprintf(stderr, "Call to JNI_CreateJavaVM failed "
"with error: %d\n", rv);
return NULL;
}
// We use findClassAndInvokeMethod here because the jclasses in
// jclasses.h have not loaded yet
jthr = findClassAndInvokeMethod(env, NULL, STATIC, NULL, HADOOP_FS,
"loadFileSystems", "()V");
if (jthr) {
printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
"FileSystem: loadFileSystems failed");
return NULL;
}
} else {
//Attach this thread to the VM
vm = vmBuf[0];
rv = (*vm)->AttachCurrentThread(vm, (void*)&env, 0);
if (rv != 0) {View on GitHub (pinned to 2add963021)
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
Example fix
# before export LIBHDFS_OPTS="-Xmx8g -XX:MaxPermSize=512m" # Call to JNI_CreateJavaVM failed with error: -4 # after (JDK8+, small container) export LIBHDFS_OPTS="-Xmx1g"
Defensive patterns
Strategy: validation
Validate before calling
/* Smoke-test the embedded JVM at startup with conservative options */
setenv("LIBHDFS_OPTS", "-Xmx512m", 0 /* do not override user */);
hdfsFS fs = hdfsConnect("default", 0);
if (!fs) return EXIT_FAILURE; /* stderr carries the JNI error code */ Try / catch
hdfsBuilder *b = hdfsNewBuilder();
hdfsBuilderSetNameNode(b, "default");
hdfsFS fs = hdfsBuilderConnect(b);
if (!fs) {
/* the JNI_CreateJavaVM code is on stderr; capture it during bring-up */
fprintf(stderr, "JVM bootstrap failed, errno=%d\n", errno);
exit(EXIT_FAILURE); /* do not retry: a half-created VM poisons the process */
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- PrintExceptionAndFree: error determining class name of excep
- error: (no exception)
- JNI_GetCreatedJavaVMs failed with error: %d
- Environment variable CLASSPATH not set!
- Call to AttachCurrentThread failed with error: %d
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/89ea76409fdcb352.
Report an issue: GitHub.