Skip to content

fix: handle virtual files in DAP breakpoint matching - #1457

Merged
angelozerr merged 1 commit into
redhat-developer:mainfrom
ericbodden:fix/dap-breakpoint-virtual-file-crash
Apr 7, 2026
Merged

angelozerr merged 1 commit into
redhat-developer:mainfrom
ericbodden:fix/dap-breakpoint-virtual-file-crash

Conversation

@ericbodden

Copy link
Copy Markdown
Contributor

Summary

Fixes #1447

DAPBreakpointHandlerBase.findBreakpoint() calls VirtualFile.toNioPath() to compare breakpoint file paths against the DAP source path. For sourceReference-backed virtual files (DAPFile extends LightVirtualFile), toNioPath() throws UnsupportedOperationException since these files exist only in memory with no filesystem path.

This uncaught exception silently kills the entire thenAcceptAsync callback in DAPClient.stopped(), preventing positionReached()/breakpointReached() from ever being called. As a result, the debugger UI does not update on any stopped event that occurs after a breakpoint has been set in a virtual file:

  • No line highlighting
  • No scopes/variables requests sent to the DAP server
  • Resume/Step buttons remain greyed out

The first stopped event (e.g. stopOnEntry) works because no breakpoints have been registered yet, so the loop in findBreakpoint() iterates over an empty list without hitting the crash.

Root cause

In DAPBreakpointHandlerBase.findBreakpoint():

if (fileInBreakpoint.toNioPath().equals(filePath) && line == lineNumber) {

DAPFile → LightVirtualFile → VirtualFile.toNioPath() throws UnsupportedOperationException.

Fix

Catch UnsupportedOperationException and fall back to comparing VirtualFile.getPath() as a string, which works for both local files and in-memory virtual files.

Test plan

  • Set stopOnEntry: true in a DAP launch config using sourceReference-backed virtual files
  • Verify first stop works (line highlighted, variables shown, Resume/Step enabled)
  • Set a breakpoint in the virtual source file
  • Click Resume — verify the debugger stops at the breakpoint with full UI update (line highlighting, variables refreshed, Resume/Step enabled)
  • Verify stepping (Step Over/Step Into) continues to work after breakpoint hit

🤖 Generated with Claude Code

if (fileInBreakpoint.toNioPath().equals(filePath) && line == lineNumber) {
return breakpoint;
try {
if (fileInBreakpoint.toNioPath().equals(filePath) && line == lineNumber) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of doing try/catch, it would be better to check fileInBreakpoint.isInLocalFileSystem()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, sorry that I missed that. Let me amend that...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@angelozerr okay like this? Seems to still work for me.

@angelozerr

Copy link
Copy Markdown
Contributor

@ericbodden nice catch! Please see my comments.

…r#1447)

DAPBreakpointHandlerBase.findBreakpoint() calls VirtualFile.toNioPath()
to compare breakpoint file paths. For sourceReference-backed virtual
files (DAPFile extends LightVirtualFile), toNioPath() throws
UnsupportedOperationException since these files have no filesystem path.

This uncaught exception silently kills the entire stopped-event handler
in DAPClient.stopped(), preventing positionReached()/breakpointReached()
from ever being called. As a result, the debugger UI does not update on
any stopped event that occurs after a breakpoint has been set in a
virtual file (no line highlighting, no scopes/variables fetch, disabled
Resume/Step buttons).

The fix catches UnsupportedOperationException and falls back to comparing
VirtualFile.getPath() as a string, which works for both local files and
in-memory virtual files.

Fixes redhat-developer#1447

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@ericbodden
ericbodden force-pushed the fix/dap-breakpoint-virtual-file-crash branch from 4d767fd to b65ce5c Compare April 7, 2026 13:52
@angelozerr

Copy link
Copy Markdown
Contributor

LGTM, thanks @ericbodden !

@angelozerr
angelozerr merged commit 660661e into redhat-developer:main Apr 7, 2026
6 checks passed
@angelozerr

Copy link
Copy Markdown
Contributor

@ericbodden could you add a link in https://github.com/redhat-developer/lsp4ij?tab=readme-ov-file#who-is-using-lsp4ij which explains that you use LSP4IJ for your DAP server.

And if you like LSP4IJ, please add a review in JetBrains Marketplace to help us to promote LSP4IJ. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot set breakpoints

2 participants