Skip to content

fix: prevent repeated BadLocationException logging#1443

Closed
sebthom wants to merge 1 commit intoeclipse-lsp4e:mainfrom
sebthom:issue-1439
Closed

fix: prevent repeated BadLocationException logging#1443
sebthom wants to merge 1 commit intoeclipse-lsp4e:mainfrom
sebthom:issue-1439

Conversation

@sebthom
Copy link
Copy Markdown
Member

@sebthom sebthom commented Dec 1, 2025

Fixes #1439

@sebthom sebthom requested a review from rubenporras December 1, 2025 18:08
Copy link
Copy Markdown
Contributor

@FlorianKroiss FlorianKroiss left a comment

Choose a reason for hiding this comment

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

Thanks for the quick PR @sebthom :)

Comment on lines +215 to +226
final int docLength = document.getLength();
if (caretOffset < 0 || caretOffset > docLength) {
// Stale caret offset after document changes, skip this highlight run.
// Logging is limited to debug/trace to avoid noisy error log entries.
if (LanguageServerPlugin.DEBUG || LanguageServerPlugin.isLogTraceEnabled()) {
LanguageServerPlugin.logWarning(
"Ignoring documentHighlight for stale caret offset " + caretOffset + " (document length " //$NON-NLS-1$ //$NON-NLS-2$
+ docLength + ')');
}
return;
}

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.

This is a lightweight version of what @rubenporras probably had in mind with checking LanguageServerWrapper.getTextDocumentVersion.
But do we actually gain something from such a check, besides a different error message being logged while debugging?
With or without this check, we are still in a race condition. So I would lean towards not performing this check at all.

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.

I thought my proposal was very simple, and will avoid the exceptions, @sebthom: do you think my proposal would not work? If it works, I would prefer that to this

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.

@sebthom sebthom closed this Dec 2, 2025
@sebthom sebthom deleted the issue-1439 branch December 2, 2025 14:28
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.

Typing at the end of the document occassionally logs BadLocationException

3 participants