{"record":{"id":"dd9451a398e955fe","repo":"NationalSecurityAgency/ghidra","slug":"url-path-must-indicate-the-repository-only","errorCode":null,"errorMessage":"URL path must indicate the repository only","messagePattern":"URL path must indicate the repository only","errorType":"exception","errorClass":"MalformedURLException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticDatabase.java","lineNumber":2068,"sourceCode":"\t\t\tbuilder.toString());\n\t}\n\n\t/**\n\t * Construct the database connection given a URL.  The URL protocol must be http, and the URL\n\t * path must contain exactly one element naming the particular repository on the server.\n\t * @param baseURL is the http URL\n\t * @throws MalformedURLException if the URL is malformed\n\t */\n\tpublic ElasticDatabase(URL baseURL) throws MalformedURLException {\n\t\tString fullURL = baseURL.toString();\n\t\tif (fullURL.startsWith(\"elastic:\")) {\n\t\t\t// https is the true protocol\n\t\t\tfullURL = \"https:\" + fullURL.substring(8);\n\t\t}\n\n\t\tString path = baseURL.getPath();\n\t\tif (!fullURL.endsWith(path)) {\n\t\t\tthrow new MalformedURLException(\"URL path must indicate the repository only\");\n\t\t}\n\t\trepository = path.substring(1);\n\t\tthis.serverInfo = new BSimServerInfo(DBType.elastic, null, baseURL.getHost(),\n\t\t\tbaseURL.getPort(), repository);\n\t\tthis.baseURL = fullURL.substring(0, fullURL.length() - path.length());\n\n\t\tlastError = null;\n\t\tinfo = null;\n\t\tstatus = Status.Unconnected;\n\t\tinitialized = false;\n\t}\n\n\t/**\n\t * @return true if a connection has been successfully initialized\n\t */\n\tpublic boolean isInitialized() {\n\t\treturn initialized;\n\t}","sourceCodeStart":2050,"sourceCodeEnd":2086,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticDatabase.java#L2050-L2086","documentation":"Thrown as a MalformedURLException in the ElasticDatabase(URL) constructor when the full URL string does not end with the URL's path component. The BSim URL format must be a simple http(s)://host:port/<repository> with exactly one path segment. Any query string, fragment, trailing slash, or multi-segment path that causes fullURL to not end with path triggers this exception.","triggerScenarios":"Constructing an ElasticDatabase with a URL whose toString() does not end with baseURL.getPath(). For example, a URL with query parameters (?param=value) causes the full string to end with the query, not the path; a URL with a fragment (#section) has the same effect.","commonSituations":"Passing a URL with authentication query parameters; URL with a trailing slash (/repo/); URL constructed by concatenating extra path segments; passing an elastic: protocol URL that was not properly normalized.","solutions":["Use a clean URL of the form http://host:port/repository with no query string, fragment, or trailing slash.","Strip query parameters and fragments before constructing the URL object.","Ensure exactly one path segment (the repository name) — no nested paths.","If using the elastic: scheme, ensure it follows the http://host:port/repository pattern after protocol normalization."],"exampleFix":"// before\nURL url = new URL(\"http://localhost:9200/myrepo?refresh=true\");\nElasticDatabase db = new ElasticDatabase(url);  // throws MalformedURLException\n\n// after\nURL url = new URL(\"http://localhost:9200/myrepo\");\nElasticDatabase db = new ElasticDatabase(url);","handlingStrategy":"validation","validationCode":"// Validate the URL before constructing ElasticDatabase\nString urlStr = baseURL.toString();\nif (urlStr.contains(\"?\") || urlStr.contains(\"#\")) {\n    throw new IllegalArgumentException(\n        \"BSim URL must not contain query parameters or fragments: \" + urlStr);\n}\nString path = baseURL.getPath();\nif (path == null || path.isEmpty() || path.equals(\"/\") || path.indexOf('/', 1) != -1) {\n    throw new IllegalArgumentException(\n        \"BSim URL path must be a single repository segment: \" + path);\n}\nif (!urlStr.endsWith(path)) {\n    throw new IllegalArgumentException(\n        \"URL must end with the repository path: \" + urlStr);\n}","typeGuard":null,"tryCatchPattern":"try {\n    ElasticDatabase db = new ElasticDatabase(new URL(urlString));\n} catch (MalformedURLException e) {\n    if (e.getMessage().contains(\"URL path must indicate the repository only\")) {\n        // Strip query/fragment and retry with a clean URL\n        urlString = urlString.replaceAll(\"[?#].*$\", \"\");\n        ElasticDatabase db = new ElasticDatabase(new URL(urlString));\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always construct BSim URLs as http://host:port/repository with no query string or fragment.","Validate the URL format before passing it to the ElasticDatabase constructor.","Centralize URL construction in a helper method to prevent malformed inputs."],"tags":["bsim","url","configuration","constructor","validation","malformed-url"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}