{"record":{"id":"175c2df4a95cb721","repo":"NationalSecurityAgency/ghidra","slug":"error-parsing-url","errorCode":null,"errorMessage":"Error parsing URL: ","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":374,"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(POST);\n\t\t\tconnection.setRequestProperty(\"Content-Type\", \"application/x-ndjson\");\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\t}\n\n\tpublic JsonObject executeURIOnly(String command, String path) throws ElasticException {\n\t\tHttpURLConnection connection = null;\n\t\ttry {\n\t\t\tURL httpURL = new URI(httpURLbase + path).toURL();","sourceCodeStart":356,"sourceCodeEnd":392,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticConnection.java#L356-L392","documentation":"URISyntaxException handler inside executeBulk. executeBulk builds its URL from the raw hostURL (NOT the repo-scoped httpURLbase) plus the path, with Content-Type application/x-ndjson. This fires when hostURL + path is not a valid URI.","triggerScenarios":"Bulk path argument (typically '_bulk' or a prefixed variant) containing a space or symbol; hostURL with a space, non-ASCII host, or trailing slash producing '//'; unencoded dynamic segment in the bulk path.","commonSituations":"Constructing the bulk path from user/derived input without encoding; copy-pasted ES URL with whitespace; mixed http/https scheme typo.","solutions":["Keep hostURL as scheme://host:port with no trailing slash and pass a literal, well-known bulk path.","Percent-encode any dynamic part of the bulk path with URLEncoder.encode(seg, UTF_8).","Pre-validate with URI.create(hostURL + path) to surface the exact bad character."],"exampleFix":"// before\nc.executeBulk(\"_bulk?refresh=true \" + userTag, ndjson);\n// after\nc.executeBulk(\"_bulk?refresh=\" + URLEncoder.encode(userTag, UTF_8), ndjson);","handlingStrategy":"validation","validationCode":"public static String safeBulkPath(String hostUrl, String path) {\n    String base = hostUrl.replaceAll(\"/+$\", \"\");\n    URI.create(base); // validate host URL\n    URI.create(base + \"/\" + path); // validate full bulk URL\n    return path;\n}","typeGuard":null,"tryCatchPattern":"try {\n    return conn.executeBulk(path, ndjson);\n} catch (ElasticException e) {\n    if (e.getMessage().startsWith(\"Error parsing URL\"))\n        throw new IllegalArgumentException(\"Invalid bulk path: \" + path, e);\n    throw e;\n}","preventionTips":["Keep hostURL as scheme://host:port with no trailing slash.","Pass a literal well-known bulk path; encode any dynamic query param.","Validate the full URL shape once at startup, not per bulk call."],"tags":["configuration","uri","validation","bsim","bulk"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}