{"record":{"id":"dbc57172eb099511","repo":"apache/hadoop","slug":"null-entry-in-command-string","errorCode":null,"errorMessage":"(null) entry in command string: {}","messagePattern":"\\(null\\) entry in command string: (.+?)","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java","lineNumber":1280,"sourceCode":"\n    /**\n     * Returns the timeout value set for the executor's sub-commands.\n     * @return The timeout value in milliseconds\n     */\n    @VisibleForTesting\n    public long getTimeoutInterval() {\n      return timeOutInterval;\n    }\n\n    /**\n     * Execute the shell command.\n     * @throws IOException if the command fails, or if the command is\n     * not well constructed.\n     */\n    public void execute() throws IOException {\n      for (String s : command) {\n        if (s == null) {\n          throw new IOException(\"(null) entry in command string: \"\n              + StringUtils.join(\" \", command));\n        }\n      }\n      this.run();\n    }\n\n    @Override\n    public String[] getExecString() {\n      return command;\n    }\n\n    @Override\n    protected void parseExecResult(BufferedReader lines) throws IOException {\n      output = new StringBuilder();\n      char[] buf = new char[512];\n      int nRead;\n      while ( (nRead = lines.read(buf, 0, buf.length)) > 0 ) {\n        output.append(buf, 0, nRead);","sourceCodeStart":1262,"sourceCodeEnd":1298,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/Shell.java#L1262-L1298","documentation":"Shell.Command.execute() — the entry point behind ShellCommandExecutor — iterates the command array and throws IOException '(null) entry in command string: ...' if any element is null, because ProcessBuilder/Runtime.exec cannot accept null arguments. It is a precondition failure on a dynamically built command line, not an OS error.","triggerScenarios":"new ShellCommandExecutor(new String[]{...}).execute() where one slot is null: an argument sourced from Configuration.get() that returned null, an env lookup that failed, or an optional flag appended without a null check.","commonSituations":"Config keys missing from site XML so get() yields null and is spliced into the exec array; refactors making a parameter @Nullable; conditional argument lists built with List.add(maybeNull).","solutions":["Read the exception message — it prints the full joined command so the null's position is visible","Trace which producer supplied the null (usually conf.get(\"key\") for an unset key) and set the key or add a default: conf.get(\"key\", \"defaultValue\")","Validate the array before execution: Arrays.stream(cmd).allMatch(Objects::nonNull)","Build commands with a small helper that skips or defaults null optional arguments"],"exampleFix":"// before\nString[] cmd = {\"bash\", scriptPath, conf.get(\"mapred.task.exec\")}; // third slot may be null\nnew ShellCommandExecutor(cmd).execute();\n\n// after\nObjects.requireNonNull(scriptPath, \"scriptPath\");\nString taskExec = conf.get(\"mapred.task.exec\", \"\");\nString[] cmd = {\"bash\", scriptPath, taskExec};\nnew ShellCommandExecutor(cmd).execute();","handlingStrategy":"validation","validationCode":"String[] cmd = {\"bash\", scriptPath, conf.get(\"some.key\", \"\")};\nif (Arrays.stream(cmd).anyMatch(Objects::isNull)) {\n  throw new IllegalArgumentException(\"Null entry in command: \" + Arrays.toString(cmd));\n}\nnew ShellCommandExecutor(cmd).execute();","typeGuard":null,"tryCatchPattern":"try { executor.execute(); } catch (IOException e) { if (e.getMessage().startsWith(\"(null) entry\")) { /* fix argument source, rebuild cmd */ } else throw e; }","preventionTips":["Always give Configuration.get() a default value when the result feeds a command array","Build command arrays via a helper that validates each add (Objects.requireNonNull)","Unit-test generated command arrays: assert no null element before executing","Log Arrays.toString(cmd) before execute() so failures show the exact offending slot"],"tags":["hadoop","shell","process","null-argument","command-execution"],"backgroundTag":"null-argument","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}