{"record":{"id":"8a4b9eefb532f9f7","repo":"apache/hadoop","slug":"port-number-invalid","errorCode":null,"errorMessage":"Port number '{}' invalid","messagePattern":"Port number '(.+?)' invalid","errorType":"exception","errorClass":"BadFencingConfigurationException","httpStatus":null,"severity":"error","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/SshFenceByTcpPort.java","lineNumber":263,"sourceCode":"        if (!m.matches()) {\n          throw new BadFencingConfigurationException(\n              \"Unable to parse user and SSH port: \"+ arg);\n        }\n        if (m.group(1) != null) {\n          user = m.group(1);\n        }\n        if (m.group(2) != null) {\n          sshPort = parseConfiggedPort(m.group(2));\n        }\n      }\n    }\n\n    private int parseConfiggedPort(String portStr)\n        throws BadFencingConfigurationException {\n      try {\n        return Integer.parseInt(portStr);\n      } catch (NumberFormatException nfe) {\n        throw new BadFencingConfigurationException(\n            \"Port number '\" + portStr + \"' invalid\");\n      }\n    }\n  }\n\n  /**\n   * Adapter from JSch's logger interface to our log4j\n   */\n  private static class LogAdapter implements com.jcraft.jsch.Logger {\n    static final Logger LOG = LoggerFactory.getLogger(\n        SshFenceByTcpPort.class.getName() + \".jsch\");\n\n    @Override\n    public boolean isEnabled(int level) {\n      switch (level) {\n      case com.jcraft.jsch.Logger.DEBUG:\n        return LOG.isDebugEnabled();\n      case com.jcraft.jsch.Logger.INFO:","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ha/SshFenceByTcpPort.java#L245-L281","documentation":"SshFenceByTcpPort.parseConfiggedPort() wraps NumberFormatException in BadFencingConfigurationException(\"Port number '<portStr>' invalid\") when the port segment of the sshfence argument passed the USER_PORT_RE regex (colon followed to end) but is not parseable by Integer.parseInt.","triggerScenarios":"An sshfence argument whose port group is non-numeric or empty in a way the regex still accepted group(2), e.g. 'sshfence(hdfs:0x16)', 'sshfence(hdfs:22 )', or oversized/out-of-range values that overflow int parsing.","commonSituations":"Typo in the port; config templating substituting a variable name instead of a number; copied example with placeholder text in the port position.","solutions":["Write a decimal TCP port between 1 and 65535, e.g. 'sshfence(hdfs:22)'.","If hdfs-site.xml is templated, verify the substituted value is numeric.","Check for stray whitespace or units in the port string."],"exampleFix":"<!-- before -->\n<value>sshfence(hdfs:SSH_PORT)</value>\n\n<!-- after -->\n<value>sshfence(hdfs:22)</value>","handlingStrategy":"validation","validationCode":"String port = arg.substring(arg.indexOf(':') + 1);\nint p = Integer.parseInt(port); // NumberFormatException if non-numeric\nif (p <= 0 || p > 65535) throw new IllegalArgumentException(\"port out of range\");","typeGuard":null,"tryCatchPattern":"try {\n  new NodeFencer(conf, \"sshfence(hdfs:\" + portStr + \")\");\n} catch (BadFencingConfigurationException e) {\n  // 'Port number invalid' -> replace with a decimal TCP port\n}","preventionTips":["Write ports as decimal numbers 1-65535 with no whitespace or units.","If configs are templated, assert substituted values are numeric in the templating tests.","Prefer relying on the default (22) over hardcoding unless sshd is nonstandard."],"tags":["hadoop","configuration","fencing","ssh","invalid-port"],"backgroundTag":"invalid-port-number","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-23T01:17:44.959Z"}