apache/hadoop · error · IOException
username == null && groupname == null
Error message
username == null && groupname == null
What it means
FileUtil.setOwner(File file, String username, String groupname) requires at least one non-null owner component; when both are null it throws IOException("username == null && groupname == null") before invoking the platform chown. This is an argument-contract check — the method cannot build a chown argument string from two nulls (the code composes arg as username + ":" + groupname).
Source
Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java:1332
LOG.debug("Error while changing permission : " + filename
+" Exception: " + StringUtils.stringifyException(e));
}
}
return shExec.getExitCode();
}
/**
* Set the ownership on a file / directory. User name and group name
* cannot both be null.
* @param file the file to change
* @param username the new user owner name
* @param groupname the new group owner name
* @throws IOException raised on errors performing I/O.
*/
public static void setOwner(File file, String username,
String groupname) throws IOException {
if (username == null && groupname == null) {
throw new IOException("username == null && groupname == null");
}
String arg = (username == null ? "" : username)
+ (groupname == null ? "" : ":" + groupname);
String [] cmd = Shell.getSetOwnerCommand(arg);
execCommand(file, cmd);
}
/**
* Platform independent implementation for {@link File#setReadable(boolean)}
* File#setReadable does not work as expected on Windows.
* @param f input file
* @param readable readable.
* @return true on success, false otherwise
*/
public static boolean setReadable(File f, boolean readable) {
if (Shell.WINDOWS) {
try {
String permission = readable ? "u+r" : "u-r";View on GitHub (pinned to 2add963021)
Solutions
- Default the nulls before calling: fall back to the current user (System.getProperty("user.name")) or its primary group
- Validate arguments up front and fail with your own descriptive error naming the missing config keys
- Skip the chown entirely when no ownership change is requested instead of calling the API with two nulls
- Audit callers that forward optional values from configuration
Example fix
// before
FileUtil.setOwner(file, userCfg, groupCfg); // both null -> IOException
// after
if (userCfg == null) userCfg = System.getProperty("user.name");
if (groupCfg != null || userCfg != null) {
FileUtil.setOwner(file, userCfg, groupCfg);
} Defensive patterns
Strategy: validation
Validate before calling
Objects.requireNonNull(username != null || groupname != null ? this : null,
"setOwner needs a user or group");
if (username == null && groupname == null) {
username = System.getProperty("user.name"); // sensible default
}
FileUtil.setOwner(file, username, groupname); Type guard
static boolean hasOwnerChange(String user, String group) {
return user != null || group != null;
} Prevention
- Validate ownership config keys at startup, not at chown time
- Skip the call entirely when no change is requested
- Default missing user/group to the process identity
When it happens
Trigger: Calling setOwner(file, null, null) directly; passing through user/group values from config or RPC that were never populated; conditional logic that computes both names to null under a missing default.
Common situations: Setup tools applying ownership from optional config keys (fs.owner, fs.group) that are unset; ported scripts where chown user was hardcoded but dropped; nulls flowing from empty map lookups.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
- Failed to set permissions of path: " + p + " to " + String.f
- Failed to rename %s to %s, file already exists or not empty!
- Unsupported block buffer "{}"
- Cannot seek to a negative offset
- Requested more bytes than destination buffer size: request l
AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22).
Data as JSON: /api/errors/a23cc5a11b5f9586.
Report an issue: GitHub.