Skip to content

Commit

Permalink
Fix NPE if ITextViewer is nullified during call to .underline()
Browse files Browse the repository at this point in the history
Previously, it was possible for the `viewer` variable used in
`LSPDocumentLinkPresentationReconcilingStrategy.underline()` to be
nullified externally, which caused a null-pointer exception for the
call `viewer.getTextWidget()`.

This commit solves this problem by saving the relevant viewer as a
variable local to the
`LSPDocumentLinkPresentationReconcilingStrategy.underline()` function.
  • Loading branch information
joaodinissf authored and mickaelistria committed Feb 14, 2024
1 parent f7b18d8 commit 0242893
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -62,10 +62,11 @@ public void uninstall() {
}

private void underline() {
if (viewer == null)
ITextViewer theViewer = viewer;
if (theViewer == null)
return;

final IDocument document = viewer.getDocument();
final IDocument document = theViewer.getDocument();
if (document == null) {
return;
}
Expand All @@ -76,7 +77,7 @@ private void underline() {
}
cancel();
final var params = new DocumentLinkParams(LSPEclipseUtils.toTextDocumentIdentifier(uri));
final Control control = viewer.getTextWidget();
final Control control = theViewer.getTextWidget();
if (control != null && !control.isDisposed()) {
Display display = control.getDisplay();
request = LanguageServers.forDocument(document)
Expand Down

0 comments on commit 0242893

Please sign in to comment.