{"record":{"id":"8a7efd0a115ccf43","repo":"NationalSecurityAgency/ghidra","slug":"port-must-be-numeric-8a7efd","errorCode":null,"errorMessage":"Port must be numeric","messagePattern":"Port must be numeric","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Debugger-jpda/src/main/java/ghidra/dbg/jdi/rmi/jpda/JdiCommands.java","lineNumber":149,"sourceCode":"\t\tstate = new State();\n\t}\n\n\tpublic void ghidraTraceConnect(String address) {\n\t\tstate.requireNoClient();\n\t\tString[] addr = address.split(\":\");\n\t\tif (addr.length != 2) {\n\t\t\tthrow new RuntimeException(\"Address must be in the form 'host:port'\");\n\t\t}\n\t\ttry {\n\t\t\tSocketChannel channel =\n\t\t\t\tSocketChannel.open(new InetSocketAddress(addr[0], Integer.parseInt(addr[1])));\n\t\t\tstate.client = new RmiClient(channel, \"jdi\");\n\t\t\tstate.client.setRegistry(connector.remoteMethodRegistry);\n\t\t\tstate.client.negotiate(\"Connect\");\n\t\t\tMsg.out(\"Connected to \" + state.client.getDescription());\n\t\t}\n\t\tcatch (NumberFormatException e) {\n\t\t\tthrow new RuntimeException(\"Port must be numeric\");\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new RuntimeException(\"Error connecting to \" + address + \": \" + e);\n\t\t}\n\t}\n\n\tpublic void ghidraTraceListen(String address) {\n\t\t// TODO: UNTESTED\n\t\tstate.requireNoClient();\n\t\tString host = \"127.0.0.1\";\n\t\tint port = 0;\n\t\tif (address != null) {\n\t\t\tString[] parts = address.split(\":\");\n\t\t\tif (parts.length == 1) {\n\t\t\t\tport = Integer.parseInt(parts[0]);\n\t\t\t}\n\t\t\telse {\n\t\t\t\thost = parts[0];","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Debugger-jpda/src/main/java/ghidra/dbg/jdi/rmi/jpda/JdiCommands.java#L131-L167","documentation":"Thrown by ghidraTraceConnect when Integer.parseInt(addr[1]) raises NumberFormatException — the port portion of the host:port address is not a valid base-10 integer. This is a distinct, more specific error than the generic connect failure so the user knows the address shape was correct but the port was non-numeric.","triggerScenarios":"Calling ghidraTraceConnect with a port like 'abc', '8080x', '12.5', or an empty port string. The host part passed the split(':' length==2 check, but the second segment is non-numeric.","commonSituations":"Typo in the port number; port specified in hex (0x1F90) which parseInt rejects; trailing whitespace or a non-printable character in the port string; a template variable was left unsubstituted producing a non-numeric value.","solutions":["Ensure the port is a plain decimal integer in the valid range 0–65535, e.g. '127.0.0.1:12345'.","Strip any whitespace or template artifacts from the address string before passing it.","If the port comes from a variable, assert it is numeric (and in range) before calling ghidraTraceConnect."],"exampleFix":"// before\nghidraTraceConnect(\"127.0.0.1:abc\"); // throws 'Port must be numeric'\n\n// after\nint port = 12345;\nghidraTraceConnect(\"127.0.0.1:\" + port);","handlingStrategy":"validation","validationCode":"String[] parts = address.split(\":\");\ntry {\n    int port = Integer.parseInt(parts[1]);\n    if (port < 0 || port > 65535) throw new IllegalArgumentException(\"Port out of range\");\n} catch (NumberFormatException e) {\n    // tell user the port is invalid before calling ghidraTraceConnect\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Parse and range-check the port before constructing the address string.","Reject non-numeric port input in the UI/config layer.","Avoid hex or suffix notation for ports."],"tags":["network","port-validation","jdi","ghidra-debug"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}