apache/hadoop · error
Expected classpath expansion length to be %zu but instead go
Error message
Expected classpath expansion length to be %zu but instead got %zu
What it means
getClassPath expands wildcards in two passes: one getClassPath_helper call sizes the buffer, a second fills it. If the length returned by the second pass differs from the first, this invariant message is printed, the buffer is freed, and setup fails. The usual cause is the directory contents changing between the two passes, since the sizing pass ran earlier.
Source
Thrown at hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfs/jni_helper.c:629
}
// 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;
}
#ifdef _LIBHDFS_JNI_HELPER_DEBUGGING_ON_
printf("===============\n");
printf("Allocated %zd for expanding classpath\n", length);
printf("Used %zu for expanding classpath\n", strlen(expandedClasspath) + 1);
printf("Expanded classpath=%s\n", expandedClasspath);
#endif
return expandedClasspath;
}
/**View on GitHub (pinned to 2add963021)
Solutions
- Retry the operation: with a stable directory the two passes agree
- Point wildcard classpath entries at versioned, immutable directories
- Pre-expand the CLASSPATH (hadoop classpath --glob) to skip the two-pass logic entirely
Defensive patterns
Strategy: retry
Try / catch
/* transient: directory changed between sizing and fill passes */
for (int attempt = 0; attempt < 3; attempt++) {
hdfsFS fs = hdfsConnect(uri, user);
if (fs) break;
if (errno != EINTERNAL) break; /* only retry JVM-bootstrap failures */
/* brief backoff; with a stable directory the two passes agree */
usleep(200 * 1000);
} Prevention
- Point wildcard classpath entries at immutable, versioned directories
- Pre-expand CLASSPATH with `hadoop classpath --glob` to skip the two-pass expansion
- Avoid upgrading jars in place while clients start
When it happens
Trigger: Jars added or removed in a wildcard directory between the sizing and filling passes; concurrent deployments writing into the same install tree while a client initializes.
Common situations: Automated upgrade jobs writing into share/hadoop/* while processes start; shared mounts used simultaneously by many clients.
Related errors
- wildcard_expandPath: on readdir %s: %s
- wildcard_expandPath: on closedir %s: %s
- wildcard_expandPath: on opendir %s: %s
- could not find method %s from class %s with signature %s
- getClassPath_helper: failed strdup: %s
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/9515e0e268d9ff54.
Report an issue: GitHub.