NationalSecurityAgency/ghidra · error · ElasticException

Error parsing URL: {message}

Error message

Error parsing URL: {message}

What it means

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.

Source

Thrown at Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/query/elastic/ElasticConnection.java:206

		HttpURLConnection connection = null;
		try {
			URL httpURL = new URI(hostURL + path).toURL();
			connection = (HttpURLConnection) httpURL.openConnection();
			connection.setRequestMethod(command);
			connection.setRequestProperty("Content-Type", "application/json");
			connection.setDoOutput(true);
			try (Writer writer = new OutputStreamWriter(connection.getOutputStream())) {
				writer.write(body);
			}
			lastResponseCode = connection.getResponseCode();
			JsonObject resp = grabResponse(connection);
			if (!lastRequestSuccessful()) {
				throw new ElasticException(parseErrorJSON(resp));
			}
			return resp;
		}
		catch (URISyntaxException e) {
			throw new ElasticException("Error parsing URL: " + e.getMessage());
		}
		catch (IOException e) {
			throw new ElasticException("Error sending request: " + e.getMessage());
		}
		catch (JsonParseException e) {
			throw new ElasticException("Error parsing response: " + e.getMessage());
		}
		finally {
			if (connection != null) {
				connection.disconnect();
			}
		}

	}

	/**
	 * Execute an elasticsearch command where we are not expecting a response
	 * @param command is the type of the command

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Fix hostURL to be a well-formed absolute URL (scheme + host [+ port]), no spaces.
  2. Percent-encode any special characters in the path segment before passing it.
  3. Validate hostURL + path with new URI(...).parseServerAuthority() before calling executeRawStatement.
  4. Strip stray whitespace from configuration values.

Example fix

// before
conn.executeRawStatement("GET", "bad path with spaces", body);

// after
String path = URLEncoder.encode("bad path with spaces", StandardCharsets.UTF_8);
conn.executeRawStatement("GET", path, body);
Defensive patterns

Strategy: validation

Validate before calling

String combined = hostURL + path;
try { new URI(combined).toURL(); }
catch (URISyntaxException e) { throw new IllegalArgumentException("bad URL: " + combined, e); }
conn.executeRawStatement(command, path, body);

Type guard

boolean isValidRequestUrl(String hostURL, String path) {
    try { new URI(hostURL + path).toURL(); return true; }
    catch (Exception e) { return false; }
}

Try / catch

try {
    conn.executeRawStatement(command, path, body);
} catch (ElasticException e) {
    if (e.getMessage().startsWith("Error parsing URL")) {
        path = URLEncoder.encode(path, StandardCharsets.UTF_8);
        conn.executeRawStatement(command, path, body);
    } else throw e;
}

Prevention

When it happens

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

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

Related errors


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