{"record":{"id":"24e763b30933f08c","repo":"apache/hadoop","slug":"detachcurrentthreadfromjvm-getjavavm-failed-with","errorCode":null,"errorMessage":"detachCurrentThreadFromJvm: GetJavaVM failed with error %d\n","messagePattern":"detachCurrentThreadFromJvm: GetJavaVM failed with error (.+?)\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/windows/thread_local_storage.c","lineNumber":55,"sourceCode":" */\nstatic void detachCurrentThreadFromJvm()\n{\n  struct ThreadLocalState *state = NULL;\n  JNIEnv *env = NULL;\n  JavaVM *vm;\n  jint ret;\n  char thr_name[MAXTHRID];\n\n  if (threadLocalStorageGet(&state) || !state) {\n    return;\n  }\n  env = state->env;\n  if ((env == NULL) || (*env == NULL)) {\n    return;\n  }\n  ret = (*env)->GetJavaVM(env, &vm);\n  if (ret) {\n    fprintf(stderr,\n      \"detachCurrentThreadFromJvm: GetJavaVM failed with error %d\\n\",\n      ret);\n    (*env)->ExceptionDescribe(env);\n  } else {\n    ret = (*vm)->DetachCurrentThread(vm);\n\n    if (ret != JNI_OK) {\n      (*env)->ExceptionDescribe(env);\n      get_current_thread_id(env, thr_name, MAXTHRID);\n\n      fprintf(stderr, \"detachCurrentThreadFromJvm: Unable to detach thread %s \"\n          \"from the JVM. Error code: %d\\n\", thr_name, ret);\n    }\n  }\n\n  /* Free exception strings */\n  if (state->lastExceptionStackTrace) free(state->lastExceptionStackTrace);\n  if (state->lastExceptionRootCause) free(state->lastExceptionRootCause);","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/os/windows/thread_local_storage.c#L37-L73","documentation":"Windows counterpart of the POSIX TLS destructor: during DLL_THREAD_DETACH/PROCESS_DETACH, detachCurrentThreadFromJvm resolves the VM with GetJavaVM before detaching; a non-zero return logs this warning and describes any pending exception. The exception strings and state are still freed afterwards, so this is a teardown-time warning.","triggerScenarios":"DLL detach after the JVM is already gone or the JNIEnv is invalid — unload ordering at process exit, or another component having detached the thread first.","commonSituations":"Windows services unloading libhdfs while JVM shutdown races; processes mixing several JNI-capable native libraries.","solutions":["If limited to process exit, treat as benign noise","If seen mid-run, audit other JNI components for double-detach","Ensure HDFS work completes before library unload"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Let libhdfs own attach/detach for threads using HDFS","Complete HDFS work before DLL unload / process exit","Suppress exit-time detach warnings in log alerting unless paired with real failures"],"tags":["libhdfs","windows","jni","thread-detach","dll"],"backgroundTag":"jni-getjavavm-failed","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}