{"record":{"id":"a21f7e4d3a47fb33","repo":"apache/hadoop","slug":"getjnienv-getglobaljnienv-failed","errorCode":null,"errorMessage":"getJNIEnv: getGlobalJNIEnv failed\n","messagePattern":"getJNIEnv: getGlobalJNIEnv failed\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c","lineNumber":849,"sourceCode":"      mutexUnlock(&jvmMutex);\n      printExceptionAndFree(state->env, jthr, PRINT_EXC_ALL,\n                            \"initCachedClasses failed\");\n      goto fail;\n    }\n\n    if (threadLocalStorageSet(state)) {\n      mutexUnlock(&jvmMutex);\n      goto fail;\n    }\n\n    // set the TLS var only when the state passes all the checks\n    THREAD_LOCAL_STORAGE_SET_QUICK(state);\n    mutexUnlock(&jvmMutex);\n\n    return state->env;\n\nfail:\n    fprintf(stderr, \"getJNIEnv: getGlobalJNIEnv failed\\n\");\n    hdfsThreadDestructor(state);\n    return NULL;\n}\n\nchar* getLastTLSExceptionRootCause()\n{\n    struct ThreadLocalState *state = NULL;\n    THREAD_LOCAL_STORAGE_GET_QUICK(&state);\n    if (!state) {\n        mutexLock(&jvmMutex);\n        if (threadLocalStorageGet(&state)) {\n            mutexUnlock(&jvmMutex);\n            return NULL;\n        }\n        mutexUnlock(&jvmMutex);\n    }\n    return state->lastExceptionRootCause;\n}","sourceCodeStart":831,"sourceCodeEnd":867,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c#L831-L867","documentation":"This is the umbrella failure at the fail label of getJNIEnv(): one of the inner bootstrap steps broke — getGlobalJNIEnv() returned NULL (see the CLASSPATH / JNI_CreateJavaVM / AttachCurrentThread messages), initCachedClasses() threw (a class-resolution failure printed just above), or threadLocalStorageSet() failed. hdfsThreadDestructor frees the partial state, getJNIEnv returns NULL, and the current API call fails with EINTERNAL. The true cause is always the stderr line printed immediately before this one.","triggerScenarios":"Any first-time per-thread init failure: missing CLASSPATH, JVM creation error, attach error, a Java exception while caching classes such as org.apache.hadoop.fs.FileSystem (classpath set but Hadoop jars missing or wrong version), or a pthread_setspecific failure.","commonSituations":"Same roots as the JVM bootstrap errors: CLASSPATH pointing at the wrong Hadoop version so classes fail to load even though the variable is set; bad LIBHDFS_OPTS; resource exhaustion. Typically seen on the first call after a deploy.","solutions":["Read the stderr line(s) directly above this message — they name the root cause (CLASSPATH, JVM code, a ClassNotFoundException/NoClassDefFoundError, or a pthread error)","If a class-loading exception appears, re-export CLASSPATH=$(hadoop classpath --glob) for the exact Hadoop version the app was linked against","If a JVM create/attach code appears, apply the fixes for those errors (LIBHDFS_OPTS, JVM alignment)","Do not chase this message itself; it only reports that init failed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"/* Startup self-test: proves CLASSPATH, JVM options, and cached classes all init */\nhdfsFS fs = hdfsConnect(\"default\", 0);\nif (!fs) return EXIT_FAILURE;\nhdfsDisconnect(fs);","typeGuard":null,"tryCatchPattern":"hdfsFS fs = hdfsConnect(\"default\", 0);\nif (!fs) {\n    /* the stderr line just above this failure names the true cause */\n    fprintf(stderr, \"libhdfs init failed (errno=%d)\\n\", errno);\n    return EXIT_FAILURE;\n}","preventionTips":["Capture the process stderr during first libhdfs use — the root-cause line precedes the umbrella message","Add a boot-time self-test (connect + hdfsExists on a known path) so init failures surface at startup","Regenerate CLASSPATH whenever the Hadoop installation is upgraded"],"tags":["libhdfs","jni","jvm-bootstrap","umbrella-error","thread-local-storage"],"backgroundTag":"jni-environment-init-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}