Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBoykoAlex2019-02-25 21:20:26 +0000
committerBoykoAlex2019-02-25 21:20:26 +0000
commitf224bb0f188dedfae175f86015e91b865d94db75 (patch)
tree7928cda12ce51491079229f99db6fe6b5c309226
parent98e59842197577be4bf273433472ad47f8badc35 (diff)
downloadlsp4e-f224bb0f188dedfae175f86015e91b865d94db75.tar.gz
lsp4e-f224bb0f188dedfae175f86015e91b865d94db75.tar.xz
lsp4e-f224bb0f188dedfae175f86015e91b865d94db75.zip
Bug 544794 - Avoid NPE for hyper links detection if doc uri is null
Signed-off-by: BoykoAlex <aboyko@pivotal.io>
-rw-r--r--org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/declaration/OpenDeclarationHyperlinkDetector.java9
-rw-r--r--org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/documentLink/DocumentLinkDetector.java9
2 files changed, 14 insertions, 4 deletions
diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/declaration/OpenDeclarationHyperlinkDetector.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/declaration/OpenDeclarationHyperlinkDetector.java
index 2b4d1fea..7dfba828 100644
--- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/declaration/OpenDeclarationHyperlinkDetector.java
+++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/declaration/OpenDeclarationHyperlinkDetector.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2016 Red Hat Inc. and others.
+ * Copyright (c) 2016, 2019 Red Hat Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
@@ -13,6 +13,7 @@
*******************************************************************************/
package org.eclipse.lsp4e.operations.declaration;
+import java.net.URI;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
@@ -75,8 +76,12 @@ public class OpenDeclarationHyperlinkDetector extends AbstractHyperlinkDetector
final IDocument document = textViewer.getDocument();
TextDocumentPositionParams params;
try {
+ URI uri = LSPEclipseUtils.toUri(document);
+ if (uri == null) {
+ return null;
+ }
params = new TextDocumentPositionParams(
- new TextDocumentIdentifier(LSPEclipseUtils.toUri(document).toString()),
+ new TextDocumentIdentifier(uri.toString()),
LSPEclipseUtils.toPosition(region.getOffset(), document));
} catch (BadLocationException e1) {
LanguageServerPlugin.logError(e1);
diff --git a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/documentLink/DocumentLinkDetector.java b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/documentLink/DocumentLinkDetector.java
index 97dda3d6..e872fa74 100644
--- a/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/documentLink/DocumentLinkDetector.java
+++ b/org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/documentLink/DocumentLinkDetector.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2017, 2018 Rogue Wave Software Inc. and others.
+ * Copyright (c) 2017, 2019 Rogue Wave Software Inc. and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
@@ -12,6 +12,7 @@
*******************************************************************************/
package org.eclipse.lsp4e.operations.documentLink;
+import java.net.URI;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
@@ -73,7 +74,11 @@ public class DocumentLinkDetector extends AbstractHyperlinkDetector {
@Override
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
final IDocument document = textViewer.getDocument();
- final DocumentLinkParams params = new DocumentLinkParams(new TextDocumentIdentifier(LSPEclipseUtils.toUri(document).toString()));
+ URI uri = LSPEclipseUtils.toUri(document);
+ if (uri == null) {
+ return null;
+ }
+ final DocumentLinkParams params = new DocumentLinkParams(new TextDocumentIdentifier(uri.toString()));
try {
return LanguageServiceAccessor
.getLanguageServers(textViewer.getDocument(),

Back to the top