NationalSecurityAgency/ghidra · error · IllegalStateException

There is no current thread

Error message

There is no current thread

What it means

Thrown by FlatDebuggerAPI.requireCurrentThread() when there is no current thread. The API documents that it is possible to have a current trace but no current thread.

Source

Thrown at Ghidra/Debug/Debugger-api/src/main/java/ghidra/debug/flatapi/FlatDebuggerAPI.java:260

	 * While uncommon, it is possible for there to be a current trace, but no current thread.
	 * 
	 * @see #getCurrentDebuggerCoordinates()
	 * @return the thread
	 */
	default TraceThread getCurrentThread() {
		return getTraceManager().getCurrentThread();
	}

	/**
	 * Get the current thread, throwing an exception if there isn't one
	 * 
	 * @return the thread
	 * @throws IllegalStateException if there is no current thread
	 */
	default TraceThread requireCurrentThread() {
		TraceThread thread = getCurrentThread();
		if (thread == null) {
			throw new IllegalStateException("There is no current thread");
		}
		return thread;
	}

	/**
	 * Require that the given thread is not null
	 * 
	 * @param thread the thread
	 * @return the thread
	 * @throws IllegalStateException if the thread is null
	 */
	default TraceThread requireThread(TraceThread thread) {
		if (thread == null) {
			throw new IllegalStateException("There is no thread");
		}
		return thread;
	}

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Guard with getCurrentThread() != null before calling thread-dependent operations.
  2. Select or pick a thread explicitly via the trace manager if one exists.
  3. Wait for or refresh the thread list before proceeding.

Example fix

// before
TraceThread th = requireCurrentThread(); // throws if none

// after
TraceThread th = getCurrentThread();
if (th == null) {
    println("No current thread");
    return;
}
Defensive patterns

Strategy: type-guard

Validate before calling

TraceThread th = getCurrentThread();
if (th == null) {
    println("No current thread; select a thread first");
    return;
}

Type guard

static boolean hasCurrentThread(FlatDebuggerAPI api) {
    return api.getCurrentThread() != null;
}

Try / catch

try {
    TraceThread th = requireCurrentThread();
} catch (IllegalStateException e) {
    if (e.getMessage().equals("There is no current thread")) {
        // pick/select a thread from the trace, then retry
    } else throw e;
}

Prevention

When it happens

Trigger: Calling requireCurrentThread() (directly or via register/memory read methods that use current coordinates) when getCurrentThread() returns null.

Common situations: Target has no threads yet (early in attach); the current thread was cleared/deselected; the target does not expose threads; process just started before thread list populated.

Related errors


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