{"record":{"id":"c56686e13b3b8d46","repo":"apache/hadoop","slug":"eio-c56686","errorCode":"EIO","errorMessage":"hdfsGetWorkingDirectory: FileSystem#getWorkingDirectory returned NULL","messagePattern":"hdfsGetWorkingDirectory: FileSystem#getWorkingDirectory returned NULL","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c","lineNumber":2918,"sourceCode":"\n    //Get the JNIEnv* corresponding to current thread\n    JNIEnv* env = getJNIEnv();\n    if (env == NULL) {\n      errno = EINTERNAL;\n      return NULL;\n    }\n\n    //FileSystem#getWorkingDirectory()\n    jthr = invokeMethod(env, &jVal, INSTANCE, jFS, JC_FILE_SYSTEM,\n            \"getWorkingDirectory\", \"()Lorg/apache/hadoop/fs/Path;\");\n    if (jthr) {\n        ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,\n            \"hdfsGetWorkingDirectory: FileSystem#getWorkingDirectory\");\n        goto done;\n    }\n    jPath = jVal.l;\n    if (!jPath) {\n        fprintf(stderr, \"hdfsGetWorkingDirectory: \"\n            \"FileSystem#getWorkingDirectory returned NULL\");\n        ret = -EIO;\n        goto done;\n    }\n\n    //Path#toString()\n    jthr = invokeMethod(env, &jVal, INSTANCE, jPath, JC_PATH, \"toString\",\n            \"()Ljava/lang/String;\");\n    if (jthr) {\n        ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,\n            \"hdfsGetWorkingDirectory: Path#toString\");\n        goto done;\n    }\n    jPathString = jVal.l;\n    jPathChars = (*env)->GetStringUTFChars(env, jPathString, NULL);\n    if (!jPathChars) {\n        ret = printPendingExceptionAndFree(env, PRINT_EXC_ALL,\n            \"hdfsGetWorkingDirectory: GetStringUTFChars\");","sourceCodeStart":2900,"sourceCodeEnd":2936,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c#L2900-L2936","documentation":"hdfsGetWorkingDirectory calls FileSystem#getWorkingDirectory over JNI. The Java contract says this never returns null (it falls back to the working/home directory), so a null Path means a broken or custom FileSystem implementation or corrupted JVM state; libhdfs prints the message and fails with ret = -EIO.","triggerScenarios":"A custom or mocked FileSystem registered in the loaded configuration whose getWorkingDirectory returns null; a JVM left in a bad state by earlier pending exceptions that were swallowed.","commonSituations":"Test harnesses registering stub FileSystem implementations; third-party filesystem connectors on the classpath overriding the method; version-mismatched hadoop jars changing behavior.","solutions":["Verify fs is a plain HDFS connection (hdfsConnect with an hdfs:// URI) and not a custom fs implementation","Check the hadoop jars on CLASSPATH match the native library version","Fall back to the conventional default working directory '/user/<user>' when the call fails with EIO"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"errno = 0;\nif (hdfsGetWorkingDirectory(fs, buf, sizeof(buf)) == NULL) {\n    /* EIO: JVM returned null Path; fall back to the conventional default */\n    snprintf(buf, sizeof(buf), \"/user/%s\", getpwuid(getuid())->pw_name);\n}","preventionTips":["Use plain hdfs:// connections rather than custom FileSystem implementations","Keep hadoop jar versions aligned with the native library"],"tags":["hdfs","libhdfs","jni","working-directory"],"backgroundTag":"jni-null-return","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}