apache/hadoop · error

EIO

EIO

Error message

hdfsGetWorkingDirectory: FileSystem#getWorkingDirectory returned NULL

What it means

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.

Source

Thrown at hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/hdfs.c:2918

    //Get the JNIEnv* corresponding to current thread
    JNIEnv* env = getJNIEnv();
    if (env == NULL) {
      errno = EINTERNAL;
      return NULL;
    }

    //FileSystem#getWorkingDirectory()
    jthr = invokeMethod(env, &jVal, INSTANCE, jFS, JC_FILE_SYSTEM,
            "getWorkingDirectory", "()Lorg/apache/hadoop/fs/Path;");
    if (jthr) {
        ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
            "hdfsGetWorkingDirectory: FileSystem#getWorkingDirectory");
        goto done;
    }
    jPath = jVal.l;
    if (!jPath) {
        fprintf(stderr, "hdfsGetWorkingDirectory: "
            "FileSystem#getWorkingDirectory returned NULL");
        ret = -EIO;
        goto done;
    }

    //Path#toString()
    jthr = invokeMethod(env, &jVal, INSTANCE, jPath, JC_PATH, "toString",
            "()Ljava/lang/String;");
    if (jthr) {
        ret = printExceptionAndFree(env, jthr, PRINT_EXC_ALL,
            "hdfsGetWorkingDirectory: Path#toString");
        goto done;
    }
    jPathString = jVal.l;
    jPathChars = (*env)->GetStringUTFChars(env, jPathString, NULL);
    if (!jPathChars) {
        ret = printPendingExceptionAndFree(env, PRINT_EXC_ALL,
            "hdfsGetWorkingDirectory: GetStringUTFChars");

View on GitHub (pinned to 2add963021)

Solutions

  1. Verify fs is a plain HDFS connection (hdfsConnect with an hdfs:// URI) and not a custom fs implementation
  2. Check the hadoop jars on CLASSPATH match the native library version
  3. Fall back to the conventional default working directory '/user/<user>' when the call fails with EIO
Defensive patterns

Strategy: fallback

Try / catch

errno = 0;
if (hdfsGetWorkingDirectory(fs, buf, sizeof(buf)) == NULL) {
    /* EIO: JVM returned null Path; fall back to the conventional default */
    snprintf(buf, sizeof(buf), "/user/%s", getpwuid(getuid())->pw_name);
}

Prevention

When it happens

Trigger: 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.

Common situations: Test harnesses registering stub FileSystem implementations; third-party filesystem connectors on the classpath overriding the method; version-mismatched hadoop jars changing behavior.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/c56686e13b3b8d46. Report an issue: GitHub.