{"record":{"id":"1c248c70ec187ec2","repo":"NationalSecurityAgency/ghidra","slug":"bad-database-url-e-getmessage","errorCode":null,"errorMessage":"Bad database URL: ${e.getMessage()}","messagePattern":"Bad database URL: (.+?)","errorType":"exception","errorClass":"QueryDatabaseException","httpStatus":null,"severity":"error","filePath":"Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/facade/SimilarFunctionQueryService.java","lineNumber":439,"sourceCode":"\t}\n\n\tpublic void initializeDatabase(String serverURLString) throws QueryDatabaseException {\n\t\tif (isSameDatabase(serverURLString)) {\n\t\t\tif (database.getStatus() == Status.Ready) {\n\t\t\t\treturn; // Trying to connect with server which is still ready\n\t\t\t}\n\t\t}\n\n\t\tif (database != null) {\n\t\t\tdatabase.close(); // Shutdown old connection (or erroneous connection)\n\t\t\tdatabase = null;\n\t\t}\n\n\t\ttry {\n\t\t\tdatabase = createDatabase(serverURLString);\n\t\t}\n\t\tcatch (MalformedURLException | URISyntaxException e) {\n\t\t\tthrow new QueryDatabaseException(\"Bad database URL: \" + e.getMessage());\n\t\t}\n\t\tboolean success = database.initialize();\n\t\tif (!success) {\n\t\t\tString errorMsg = \"\";\n\t\t\tif (database.getLastError() != null) {\n\t\t\t\terrorMsg = database.getLastError().message;\n\t\t\t}\n\n\t\t\tthrow new QueryDatabaseException(errorMsg);\n\t\t}\n\t}\n\n\tprivate boolean isSameDatabase(String serverURLString) {\n\t\tif (database == null) {\n\t\t\treturn false;\n\t\t}\n\t\treturn database.getURLString().equals(serverURLString);\n\t}","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/facade/SimilarFunctionQueryService.java#L421-L457","documentation":"Thrown as a QueryDatabaseException when BSimClientFactory.deriveBSimURL() or BSimClientFactory.buildClient() throws MalformedURLException or URISyntaxException during initializeDatabase(). This means the server URL string provided to the SimilarFunctionQueryService does not conform to a valid BSim URL scheme (e.g., 'h2://', 'postgresql://', 'https://').","triggerScenarios":"Calling initializeDatabase(serverURLString) with a malformed URL string. Examples: missing protocol prefix, unsupported scheme (e.g., 'mysql://'), unencoded special characters, typos like 'postgress://', or a path that violates URI syntax rules (spaces, brackets).","commonSituations":"User types a BSim server URL into the Ghidra GUI BSim dialog with a typo. Configuration file contains a stale or hand-edited URL. Script passes a constructed string with unescaped characters. Using a scheme not supported by the installed BSim client factory.","solutions":["Correct the URL scheme to a supported BSim protocol: 'h2://<path>', 'postgresql://<host>:<port>/<dbname>', or 'https://<host>:<port>/<dbname>'.","Ensure no leading/trailing whitespace or stray characters in the URL string.","URL-encode any special characters in the path or query parameters.","Validate the URL format before passing it to initializeDatabase()."],"exampleFix":"// before\nString url = \"postgress://localhost:8080/mydb\"; // typo in scheme\nservice.initializeDatabase(url);\n\n// after\nString url = \"postgresql://localhost:8080/mydb\";\nservice.initializeDatabase(url);","handlingStrategy":"validation","validationCode":"// Validate BSim URL format before passing to initializeDatabase\nString url = serverURLString.trim();\nif (!url.startsWith(\"h2://\") && !url.startsWith(\"postgresql://\") && !url.startsWith(\"https://\")) {\n    throw new IllegalArgumentException(\n        \"Unsupported BSim URL scheme. Use h2://, postgresql://, or https://\");\n}\ntry {\n    new URI(url);\n} catch (URISyntaxException e) {\n    throw new IllegalArgumentException(\"Invalid BSim URL: \" + e.getMessage());\n}","typeGuard":null,"tryCatchPattern":"try {\n    service.initializeDatabase(url);\n} catch (QueryDatabaseException e) {\n    if (e.getMessage().startsWith(\"Bad database URL:\")) {\n        // URL syntax issue — fix the URL, no point retrying\n        showErrorDialog(\"Invalid BSim Server URL\", e.getMessage());\n        return;\n    }\n    throw e;\n}","preventionTips":["Always validate the URL scheme (h2://, postgresql://, https://) before calling initializeDatabase().","Provide a UI dropdown or picker for the protocol rather than free-text URL entry.","Trim whitespace from user-entered URLs before processing.","Store validated BSim URLs in a config file rather than re-typing them each session."],"tags":["bsim","url","configuration","validation"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}