NationalSecurityAgency/ghidra · error · RuntimeException

Already connected

Error message

Already connected

What it means

RuntimeException('Already connected') thrown by State.requireNoClient() when client is already non-null. Notably the method first sets client = null and then throws, so a duplicate connect attempt both clears the existing connection and signals the error. It guards connect-style commands that expect a clean (disconnected) state.

Source

Thrown at Ghidra/Debug/Debugger-jpda/src/main/java/ghidra/dbg/jdi/rmi/jpda/JdiCommands.java:73

 */

class State {

	public RmiClient client;
	public RmiTrace trace;
	RmiTransaction tx;

	public RmiClient requireClient() {
		if (client == null) {
			throw new RuntimeException("Not connected");
		}
		return client;
	}

	public void requireNoClient() {
		if (client != null) {
			client = null;
			throw new RuntimeException("Already connected");
		}
	}

	public void resetClient() {
		client = null;
		resetTrace();
	}

	public RmiTrace requireTrace() {
		if (trace == null) {
			throw new RuntimeException("No trace started");
		}
		return trace;
	}

	public void requireNoTrace() {
		if (trace != null) {
			throw new RuntimeException("Trace already started");

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Disconnect/reset the client (resetClient or the disconnect command) before issuing another connect.
  2. Check state.client == null before attempting connect; if non-null, reuse the existing connection.
  3. Be aware that hitting this error already nulled the prior client, so you must reconnect afterward.

Example fix

// before
// connect called again while already connected -> 'Already connected' AND client cleared

// after
if (state.client != null) {
    state.resetClient(); // explicit disconnect first
}
connect(...);
Defensive patterns

Strategy: validation

Validate before calling

if (state.client != null) {
    state.resetClient(); // disconnect cleanly before reconnecting
}
connect(...);

Try / catch

try {
    state.requireNoClient();
} catch (RuntimeException e) {
    if ("Already connected".equals(e.getMessage())) {
        // note: client was just nulled; must reconnect
    }
}

Prevention

When it happens

Trigger: Calling a connect/setup command that routes through requireNoClient() while State.client is already set (a previous connect succeeded and was not disconnected).

Common situations: Issuing connect twice in a row; reconnecting without first disconnecting; a command sequence that assumes a fresh session but one is already live.

Related errors


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