{"record":{"id":"52fda8a777bb42f3","repo":"NationalSecurityAgency/ghidra","slug":"error-parsing-url-message","errorCode":null,"errorMessage":"Error parsing URL: {message}","messagePattern":"Error parsing URL: (.+?)","errorType":"exception","errorClass":"ElasticException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticConnection.java","lineNumber":206,"sourceCode":"\t\tHttpURLConnection connection = null;\n\t\ttry {\n\t\t\tURL httpURL = new URI(hostURL + path).toURL();\n\t\t\tconnection = (HttpURLConnection) httpURL.openConnection();\n\t\t\tconnection.setRequestMethod(command);\n\t\t\tconnection.setRequestProperty(\"Content-Type\", \"application/json\");\n\t\t\tconnection.setDoOutput(true);\n\t\t\ttry (Writer writer = new OutputStreamWriter(connection.getOutputStream())) {\n\t\t\t\twriter.write(body);\n\t\t\t}\n\t\t\tlastResponseCode = connection.getResponseCode();\n\t\t\tJsonObject resp = grabResponse(connection);\n\t\t\tif (!lastRequestSuccessful()) {\n\t\t\t\tthrow new ElasticException(parseErrorJSON(resp));\n\t\t\t}\n\t\t\treturn resp;\n\t\t}\n\t\tcatch (URISyntaxException e) {\n\t\t\tthrow new ElasticException(\"Error parsing URL: \" + e.getMessage());\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new ElasticException(\"Error sending request: \" + e.getMessage());\n\t\t}\n\t\tcatch (JsonParseException e) {\n\t\t\tthrow new ElasticException(\"Error parsing response: \" + e.getMessage());\n\t\t}\n\t\tfinally {\n\t\t\tif (connection != null) {\n\t\t\t\tconnection.disconnect();\n\t\t\t}\n\t\t}\n\n\t}\n\n\t/**\n\t * Execute an elasticsearch command where we are not expecting a response\n\t * @param command is the type of the command","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticConnection.java#L188-L224","documentation":"Thrown by ElasticConnection.executeRawStatement when constructing the request URL (hostURL + path) raises a URISyntaxException. The hostURL or the appended path is not a valid URI reference, so new URI(...).toURL() fails before any network call. This is a client-side configuration/input error, not a server error.","triggerScenarios":"executeRawStatement with a hostURL or path containing illegal URI characters (spaces, unencoded special chars, bad scheme). new URI(hostURL + path).toURL() throws URISyntaxException, caught and rewrapped as ElasticException.","commonSituations":"hostURL configured with spaces or missing scheme; path argument containing raw query characters that are not percent-encoded; a trailing/leading slash mismatch producing an invalid reference; copy-paste error in the BSim server URL setting.","solutions":["Fix hostURL to be a well-formed absolute URL (scheme + host [+ port]), no spaces.","Percent-encode any special characters in the path segment before passing it.","Validate hostURL + path with new URI(...).parseServerAuthority() before calling executeRawStatement.","Strip stray whitespace from configuration values."],"exampleFix":"// before\nconn.executeRawStatement(\"GET\", \"bad path with spaces\", body);\n\n// after\nString path = URLEncoder.encode(\"bad path with spaces\", StandardCharsets.UTF_8);\nconn.executeRawStatement(\"GET\", path, body);","handlingStrategy":"validation","validationCode":"String combined = hostURL + path;\ntry { new URI(combined).toURL(); }\ncatch (URISyntaxException e) { throw new IllegalArgumentException(\"bad URL: \" + combined, e); }\nconn.executeRawStatement(command, path, body);","typeGuard":"boolean isValidRequestUrl(String hostURL, String path) {\n    try { new URI(hostURL + path).toURL(); return true; }\n    catch (Exception e) { return false; }\n}","tryCatchPattern":"try {\n    conn.executeRawStatement(command, path, body);\n} catch (ElasticException e) {\n    if (e.getMessage().startsWith(\"Error parsing URL\")) {\n        path = URLEncoder.encode(path, StandardCharsets.UTF_8);\n        conn.executeRawStatement(command, path, body);\n    } else throw e;\n}","preventionTips":["Keep hostURL a well-formed absolute URL with no spaces.","Percent-encode special characters in path segments.","Validate the combined URI parses before issuing requests."],"tags":["bsim","elastic","url","validation","java"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}