Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Argument for @NotNull parameter 'cancellationSupport' of com/redhat/devtools/lsp4ij/features/highlight/LSPHighlightSupport.getHighlights must not be null #500

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package com.redhat.devtools.lsp4ij.features;

import com.redhat.devtools.lsp4ij.internal.CancellationSupport;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -84,8 +85,9 @@ protected synchronized CompletableFuture<Result> load(Params params) {
// Cancel previous LSP requests future
cancel();
// Load a new LSP requests future
cancellationSupport = new CancellationSupport();
return doLoad(params, cancellationSupport);
CancellationSupport cancellation = new CancellationSupport(); // Store the CancellationSupport in a local variable to prevent from NPE (very rare case)
cancellationSupport = cancellation;
return doLoad(params, cancellation);
}

/**
Expand All @@ -95,7 +97,7 @@ protected synchronized CompletableFuture<Result> load(Params params) {
* @param cancellationSupport the cancellation support.
* @return the LSP response results.
*/
protected abstract CompletableFuture<Result> doLoad(Params params, CancellationSupport cancellationSupport);
protected abstract CompletableFuture<Result> doLoad(Params params, @NotNull CancellationSupport cancellationSupport);

/**
* Cancel all LSP requests.
Expand All @@ -106,8 +108,7 @@ public void cancel() {
future.cancel(true);
}
this.future = null;
// Store the CancellationSupport in a local variable to prevent from NPE (very rare case)
CancellationSupport cancellation = cancellationSupport;
CancellationSupport cancellation = cancellationSupport; // Store the CancellationSupport in a local variable to prevent from NPE (very rare case)
if (cancellation != null) {
cancellation.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ public LSPHighlightSupport(@NotNull PsiFile file) {
super(file);
}

public CompletableFuture<List<DocumentHighlight>> getHighlights(DocumentHighlightParams params) {
public CompletableFuture<List<DocumentHighlight>> getHighlights(@NotNull DocumentHighlightParams params) {
return super.getFeatureData(params);
}

@Override
protected CompletableFuture<List<DocumentHighlight>> doLoad(DocumentHighlightParams params, CancellationSupport cancellationSupport) {
protected CompletableFuture<List<DocumentHighlight>> doLoad(@NotNull DocumentHighlightParams params,
@NotNull CancellationSupport cancellationSupport) {
PsiFile file = super.getFile();
return getHighlights(file.getVirtualFile(), file.getProject(), params, cancellationSupport);
}
Expand Down
Loading