NationalSecurityAgency/ghidra · error · QueryDatabaseException

Bad database URL: ${e.getMessage()}

Error message

Bad database URL: ${e.getMessage()}

What it means

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://').

Source

Thrown at Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/facade/SimilarFunctionQueryService.java:439

	}

	public void initializeDatabase(String serverURLString) throws QueryDatabaseException {
		if (isSameDatabase(serverURLString)) {
			if (database.getStatus() == Status.Ready) {
				return; // Trying to connect with server which is still ready
			}
		}

		if (database != null) {
			database.close(); // Shutdown old connection (or erroneous connection)
			database = null;
		}

		try {
			database = createDatabase(serverURLString);
		}
		catch (MalformedURLException | URISyntaxException e) {
			throw new QueryDatabaseException("Bad database URL: " + e.getMessage());
		}
		boolean success = database.initialize();
		if (!success) {
			String errorMsg = "";
			if (database.getLastError() != null) {
				errorMsg = database.getLastError().message;
			}

			throw new QueryDatabaseException(errorMsg);
		}
	}

	private boolean isSameDatabase(String serverURLString) {
		if (database == null) {
			return false;
		}
		return database.getURLString().equals(serverURLString);
	}

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Correct the URL scheme to a supported BSim protocol: 'h2://<path>', 'postgresql://<host>:<port>/<dbname>', or 'https://<host>:<port>/<dbname>'.
  2. Ensure no leading/trailing whitespace or stray characters in the URL string.
  3. URL-encode any special characters in the path or query parameters.
  4. Validate the URL format before passing it to initializeDatabase().

Example fix

// before
String url = "postgress://localhost:8080/mydb"; // typo in scheme
service.initializeDatabase(url);

// after
String url = "postgresql://localhost:8080/mydb";
service.initializeDatabase(url);
Defensive patterns

Strategy: validation

Validate before calling

// Validate BSim URL format before passing to initializeDatabase
String url = serverURLString.trim();
if (!url.startsWith("h2://") && !url.startsWith("postgresql://") && !url.startsWith("https://")) {
    throw new IllegalArgumentException(
        "Unsupported BSim URL scheme. Use h2://, postgresql://, or https://");
}
try {
    new URI(url);
} catch (URISyntaxException e) {
    throw new IllegalArgumentException("Invalid BSim URL: " + e.getMessage());
}

Try / catch

try {
    service.initializeDatabase(url);
} catch (QueryDatabaseException e) {
    if (e.getMessage().startsWith("Bad database URL:")) {
        // URL syntax issue — fix the URL, no point retrying
        showErrorDialog("Invalid BSim Server URL", e.getMessage());
        return;
    }
    throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/1c248c70ec187ec2. Report an issue: GitHub.