{"record":{"id":"a23cc5a11b5f9586","repo":"apache/hadoop","slug":"username-null-groupname-null","errorCode":null,"errorMessage":"username == null && groupname == null","messagePattern":"username == null && groupname == null","errorType":"validation","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java","lineNumber":1332,"sourceCode":"        LOG.debug(\"Error while changing permission : \" + filename\n                  +\" Exception: \" + StringUtils.stringifyException(e));\n      }\n    }\n    return shExec.getExitCode();\n  }\n\n  /**\n   * Set the ownership on a file / directory. User name and group name\n   * cannot both be null.\n   * @param file the file to change\n   * @param username the new user owner name\n   * @param groupname the new group owner name\n   * @throws IOException raised on errors performing I/O.\n   */\n  public static void setOwner(File file, String username,\n      String groupname) throws IOException {\n    if (username == null && groupname == null) {\n      throw new IOException(\"username == null && groupname == null\");\n    }\n    String arg = (username == null ? \"\" : username)\n        + (groupname == null ? \"\" : \":\" + groupname);\n    String [] cmd = Shell.getSetOwnerCommand(arg);\n    execCommand(file, cmd);\n  }\n\n  /**\n   * Platform independent implementation for {@link File#setReadable(boolean)}\n   * File#setReadable does not work as expected on Windows.\n   * @param f input file\n   * @param readable readable.\n   * @return true on success, false otherwise\n   */\n  public static boolean setReadable(File f, boolean readable) {\n    if (Shell.WINDOWS) {\n      try {\n        String permission = readable ? \"u+r\" : \"u-r\";","sourceCodeStart":1314,"sourceCodeEnd":1350,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java#L1314-L1350","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nFileUtil.setOwner(file, userCfg, groupCfg); // both null -> IOException\n\n// after\nif (userCfg == null) userCfg = System.getProperty(\"user.name\");\nif (groupCfg != null || userCfg != null) {\n  FileUtil.setOwner(file, userCfg, groupCfg);\n}","handlingStrategy":"validation","validationCode":"Objects.requireNonNull(username != null || groupname != null ? this : null,\n    \"setOwner needs a user or group\");\nif (username == null && groupname == null) {\n  username = System.getProperty(\"user.name\"); // sensible default\n}\nFileUtil.setOwner(file, username, groupname);","typeGuard":"static boolean hasOwnerChange(String user, String group) {\n  return user != null || group != null;\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["invalid-argument","null-check","set-owner","posix","fileutil"],"backgroundTag":"missing-required-parameter","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}