From c928b61c31f98d1c00084b8b39e7d76d911b3029 Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Tue, 12 Mar 2019 10:11:02 +0100 Subject: [PATCH] avoid NPE in case of document being null --- .../commons/HighlightsCodeLensProvider.java | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/HighlightsCodeLensProvider.java b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/HighlightsCodeLensProvider.java index c0c32c8ae..5f267948c 100644 --- a/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/HighlightsCodeLensProvider.java +++ b/eclipse-language-servers/org.springframework.tooling.ls.eclipse.commons/src/org/springframework/tooling/ls/eclipse/commons/HighlightsCodeLensProvider.java @@ -73,29 +73,33 @@ public class HighlightsCodeLensProvider extends AbstractCodeMiningProvider { IPreferenceStore store = LanguageServerCommonsActivator.getInstance().getPreferenceStore(); if (store.getBoolean(PreferenceConstants.HIGHLIGHT_CODELENS_PREFS)) { IDocument document = viewer.getDocument(); - - return CompletableFuture.supplyAsync(() -> { - List docInfos = LanguageServiceAccessor.getLSPDocumentInfosFor(document, (x) -> true); - if (!docInfos.isEmpty()) { - LSPDocumentInfo info = docInfos.get(0); - HighlightParams highlights = STS4LanguageClientImpl.currentHighlights.get(info.getFileUri().toString()); - if (highlights != null) { - return highlights.getCodeLenses().stream() - .filter(codeLens -> codeLens.getCommand() != null) - .map(codeLens -> { - try { - return new HighlightCodeMining(codeLens, document, this, action(codeLens.getCommand())); - } catch (BadLocationException e) { - LanguageServerCommonsActivator.logError(e, "Failed to create Eclipse client CodeLens"); - return null; - } - }) - .filter(Objects::nonNull) - .collect(Collectors.toList()); + if (document != null) { + return CompletableFuture.supplyAsync(() -> { + List docInfos = LanguageServiceAccessor.getLSPDocumentInfosFor(document, (x) -> true); + if (!docInfos.isEmpty()) { + LSPDocumentInfo info = docInfos.get(0); + HighlightParams highlights = STS4LanguageClientImpl.currentHighlights.get(info.getFileUri().toString()); + if (highlights != null) { + return highlights.getCodeLenses().stream() + .filter(codeLens -> codeLens.getCommand() != null) + .map(codeLens -> { + try { + return new HighlightCodeMining(codeLens, document, this, action(codeLens.getCommand())); + } catch (BadLocationException e) { + LanguageServerCommonsActivator.logError(e, "Failed to create Eclipse client CodeLens"); + return null; + } + }) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } } - } + return null; + }); + } + else { return null; - }); + } } return null; }