From ad312d0c97a86572459976f3f6484775a7c5248b Mon Sep 17 00:00:00 2001 From: azerr Date: Fri, 30 Aug 2024 15:53:49 +0200 Subject: [PATCH] fix: Argument for @NotNull parameter 'cancellationSupport' of com/redhat/devtools/lsp4ij/features/highlight/LSPHighlightSupport.getHighlights must not be null Fixes #486 Signed-off-by: azerr --- .../lsp4ij/features/AbstractLSPFeatureSupport.java | 11 ++++++----- .../features/highlight/LSPHighlightSupport.java | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/redhat/devtools/lsp4ij/features/AbstractLSPFeatureSupport.java b/src/main/java/com/redhat/devtools/lsp4ij/features/AbstractLSPFeatureSupport.java index ec8ff2d89..f90c48b07 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/features/AbstractLSPFeatureSupport.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/features/AbstractLSPFeatureSupport.java @@ -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; @@ -84,8 +85,9 @@ protected synchronized CompletableFuture 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); } /** @@ -95,7 +97,7 @@ protected synchronized CompletableFuture load(Params params) { * @param cancellationSupport the cancellation support. * @return the LSP response results. */ - protected abstract CompletableFuture doLoad(Params params, CancellationSupport cancellationSupport); + protected abstract CompletableFuture doLoad(Params params, @NotNull CancellationSupport cancellationSupport); /** * Cancel all LSP requests. @@ -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(); } diff --git a/src/main/java/com/redhat/devtools/lsp4ij/features/highlight/LSPHighlightSupport.java b/src/main/java/com/redhat/devtools/lsp4ij/features/highlight/LSPHighlightSupport.java index f9a31fef6..233b577a8 100644 --- a/src/main/java/com/redhat/devtools/lsp4ij/features/highlight/LSPHighlightSupport.java +++ b/src/main/java/com/redhat/devtools/lsp4ij/features/highlight/LSPHighlightSupport.java @@ -41,12 +41,13 @@ public LSPHighlightSupport(@NotNull PsiFile file) { super(file); } - public CompletableFuture> getHighlights(DocumentHighlightParams params) { + public CompletableFuture> getHighlights(@NotNull DocumentHighlightParams params) { return super.getFeatureData(params); } @Override - protected CompletableFuture> doLoad(DocumentHighlightParams params, CancellationSupport cancellationSupport) { + protected CompletableFuture> doLoad(@NotNull DocumentHighlightParams params, + @NotNull CancellationSupport cancellationSupport) { PsiFile file = super.getFile(); return getHighlights(file.getVirtualFile(), file.getProject(), params, cancellationSupport); }