Repository navigation
Description
What happens
When a DAP debug session stops at a breakpoint and the editor shows inline values, the IDE often reports an "IDE error occurred". The inline values themselves are still shown.
Steps, with LSP4IJ main (21a3f42) in a runIde sandbox (IC 2024.2):
- A Python file with a loop, a DAP run configuration with debugpy (
python -m debugpy.adapter), "Show values inline" on (the default). - A line breakpoint inside the loop, start debugging, resume a few times.
Claude Code tried this: in 9 stops the error came 4 times, at 3 of the stops (twice at the first stop, once for each of the two locals). So it comes often, but not every time.
SEVERE - #c.i.u.c.ThreadingAssertions - Read access is allowed from inside read-action only (see Application.runReadAction())
Current thread: Thread[#67,ApplicationImpl pooled thread 2,4,main] (EventQueue.isDispatchThread()=false)
at com.intellij.util.concurrency.ThreadingAssertions.softAssertReadAccess(ThreadingAssertions.java:129)
at com.intellij.openapi.fileEditor.impl.FileDocumentManagerBase.getDocument(FileDocumentManagerBase.java:49)
at com.intellij.xdebugger.impl.ui.tree.nodes.XValueNodeImpl$1.computed(XValueNodeImpl.java:133)
at com.redhat.devtools.lsp4ij.dap.client.variables.DAPValue.lambda$computeSourcePosition$2(DAPValue.java:141)
at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:718)
...
Plugin to blame: LSP4IJ version: 0.30.0-SNAPSHOT
Cause
DAPValue.computeInlineDebuggerData passes the platform's callback to computeSourcePosition. That method calls the callback in a thenAccept on the future of DAPStackFrame.getSourcePositionFor, so on whichever thread completes that future:
- If the variables context of the frame is still loading (the language servers' inline values, then
configureContexton a pooled thread), the future completes later on a pooled thread, and the callback runs there without a read action. - If it is already loaded,
thenAcceptruns at once on the calling thread, the EDT, and there is no error.
That is why the error comes mostly at the first stop, and not every time.
New in 0.30.0. In 0.21.0, getVariablesContextSync completed the future inside runReadAction (0.21.0), so the dependent thenApply/thenAccept ran in that read action. #1781 (7469aab) split the loading into loadContext without a read action and configureContext in a read action (now), and the future now completes after the read action has ended. The thenAccept in DAPValue has not changed.
The inline callback in XValueNodeImpl.updateInlineDebuggerData (2024.2) calls FileDocumentManager.getDocument(file), which needs read access. XInlineDebuggerDataCallback.computed says nothing about threads, but the platform's own debuggers call it in a read action: JavaValue.computeSourcePosition calls the navigatable inside ReadAction.nonBlocking(...). The check is a soft assertion, so getDocument still returns the document and the inline value is shown. Only the error is reported.
Newer IDEs: in IntelliJ IDEA 2026.3 the callback in XValueNodeImpl still calls getDocument without its own read action. With the split debugger, the backend callback only sends the position to the frontend over a channel, and the frontend calls computed on the EDT, so the error does not show there. Without the split debugger (older IDEs, and the monolith mode), it does.
"Jump to Source" goes through the same computeSourcePosition, but its navigatable (XJumpToSourceActionBase) moves to the UI thread itself, so it is not affected. The other async callbacks in dap/client/variables (DAPVariableChildren, DAPLazyValueEvaluator, DAPValueModifier) call node and callback methods that the platform runs on the right thread itself.
Suggestion
Call the navigatable in a read action, as JavaValue does:
@Override
public void computeSourcePosition(@NotNull XNavigatable navigatable) {
stackFrame
.getSourcePositionFor(variable)
.thenAccept(sourcePosition -> {
if (sourcePosition != null) {
ReadAction.run(() -> navigatable.setSourcePosition(sourcePosition));
}
});
}On the EDT (context already loaded) ReadAction.run costs nothing. On a pooled thread it waits only for a running write action. The callback does little work: it compares files, gets the document and schedules the inlay with invokeLater.
Also, DebugVariableContext.getSourcePosition reads editor.getDocument() to turn a text range into a line in getSourcePositionFor's thenApply, also outside a read action. The platform does not assert there, but getSourcePositionFor could run context.getSourcePositionFor(variable) in ReadAction.compute too.
A regression test is possible: move the thenAccept body into a small package-private static method (future + navigatable), and in a BasePlatformTestCase complete the future from a pooled thread with a navigatable that checks ApplicationManager.getApplication().isReadAccessAllowed(). This does not need a DAPStackFrame or a debug adapter.
How it was checked
Claude Code found and reproduced this with LSP4IJ main (21a3f42) in a runIde sandbox (IC 2024.2) and the debugpy adapter, and read XValueNodeImpl, XValue, JavaValue, XJumpToSourceActionBase and XDebuggerInlayUtil in the 2024.2 sources, and XValueNodeImpl, FrontendXValue and BackendXValueApi in the IntelliJ IDEA 2026.3 bytecode.
Activity
fix(dap): give the source position of a DAP value in a read action (r…
feat: jump from a DAP variable to its declaration, with the locations…