apache/hadoop · error

getClassPath: failed calloc: %s

Error message

getClassPath: failed calloc: %s

What it means

After a sizing pass computes the expanded classpath length, getClassPath allocates the result buffer with calloc(length, 1). On failure it prints 'failed calloc: ...' with strerror(errno) and returns NULL, so the expanded classpath is never built and the JVM is not created.

Source

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

        if ((length == 0) && (strlen(classpath) != 0)) {
            fprintf(stderr, "Something went wrong with getting the wildcard \
              expansion length\n" );
        }
#endif

        expandedClasspath = strdup(classpath);

#ifdef _LIBHDFS_JNI_HELPER_DEBUGGING_ON_
        printf("Expanded classpath=%s\n", expandedClasspath);
#endif

        return expandedClasspath;
    }

    // Allocte memory for expanded classpath string
    expandedClasspath = calloc(length, sizeof(char));
    if (expandedClasspath == NULL) {
        fprintf(stderr, "getClassPath: failed calloc: %s\n", strerror(errno));
        return NULL;
    }

    // Actual expansion
    retval = getClassPath_helper(classpath, expandedClasspath);
    if (retval < 0) {
        free(expandedClasspath);
        return NULL;
    }

    // This should not happen, but dotting i's and crossing t's
    if (retval != length) {
        fprintf(stderr,
          "Expected classpath expansion length to be %zu but instead got %zu\n",
          length, retval);
        free(expandedClasspath);
        return NULL;
    }

View on GitHub (pinned to 2add963021)

Solutions

  1. Pre-expand and shorten the CLASSPATH so the calloc is small or unnecessary
  2. Raise memory limits before the first libhdfs call
  3. Replace wildcard entries with explicit jar lists
Defensive patterns

Strategy: fallback

Try / catch

if (hdfsConnect(uri, user) == NULL && errno == EINTERNAL) {
    /* check stderr for 'failed calloc': shrink/expand wildcard entries or raise limits */
}

Prevention

When it happens

Trigger: Very large wildcard-expanded classpaths (the buffer can be megabytes) with insufficient free memory; ulimit -v or cgroup caps hit during allocation.

Common situations: Big Hadoop installations expanded via wildcards; constrained containers; the same conditions that cause the earlier strdup failure.

Related errors


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