apache/hadoop · error
getClassPath_helper: failed strdup: %s
Error message
getClassPath_helper: failed strdup: %s
What it means
getClassPath_helper begins by duplicating the CLASSPATH value with strdup so it can tokenize it with strtok. If the duplication fails, 'failed strdup: ...' is printed with strerror(errno) and -1 is returned, aborting classpath preparation and therefore JVM creation on the first libhdfs call.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c:501
/**
* Helper to expand classpaths. Returns the total length of the expanded
* classpath. If expandedClasspath is not NULL, then fills that with the
* expanded classpath. It assumes that expandedClasspath is of correct size, eg
* allocated after using this function with expandedClasspath=NULL to get the
* right size.
*/
static ssize_t getClassPath_helper(const char *classpath, char* expandedClasspath)
{
ssize_t length;
ssize_t retval;
char* expandedCP_curr;
char* cp_token;
char* classpath_dup;
classpath_dup = strdup(classpath);
if (classpath_dup == NULL) {
fprintf(stderr, "getClassPath_helper: failed strdup: %s\n",
strerror(errno));
return -1;
}
length = 0;
// expandedCP_curr is the current pointer
expandedCP_curr = expandedClasspath;
cp_token = strtok(classpath_dup, PATH_SEPARATOR_STR);
while (cp_token != NULL) {
size_t tokenlen;
#ifdef _LIBHDFS_JNI_HELPER_DEBUGGING_ON_
printf("%s\n", cp_token);
#endif
tokenlen = strlen(cp_token);View on GitHub (pinned to 2add963021)
Solutions
- Raise memory limits or free memory before the first libhdfs call (JVM init is lazy)
- Trim the CLASSPATH to only the required jars
Defensive patterns
Strategy: fallback
Validate before calling
/* fail fast when the environment is oversized or memory is scarce */
const char *cp = getenv("CLASSPATH");
if (cp && strlen(cp) > 1 * 1024 * 1024) { /* trim before JVM init */ } Try / catch
if (hdfsConnect(uri, user) == NULL && errno == EINTERNAL) {
/* check stderr for 'failed strdup': free memory or shorten CLASSPATH, then retry once */
} Prevention
- Keep CLASSPATH minimal and versioned
- Provision enough memory before JVM bootstrap, which happens lazily on first libhdfs call
When it happens
Trigger: Process heap exhausted at JVM-initialization time; an extremely large CLASSPATH string combined with tight memory limits.
Common situations: Machine-generated multi-megabyte CLASSPATH variables; memory-capped containers starting processes that use libhdfs.
Related errors
- getClassPath: failed calloc: %s
- could not find method %s from class %s with signature %s
- wildcard_expandPath: on readdir %s: %s
- wildcard_expandPath: on closedir %s: %s
- wildcard_expandPath: on opendir %s: %s
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/16906b22230f6201.
Report an issue: GitHub.