From 45e1155cf3a32f47dcf9df3709e6d9408d637be5 Mon Sep 17 00:00:00 2001 From: Kris De Volder Date: Wed, 23 Nov 2016 11:12:29 -0800 Subject: [PATCH] Fix NPE in hover info. --- .../yaml/hover/YamlHoverInfoProvider.java | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/vscode-extensions/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/hover/YamlHoverInfoProvider.java b/vscode-extensions/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/hover/YamlHoverInfoProvider.java index 1ee8d0d22..40c56d3d6 100644 --- a/vscode-extensions/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/hover/YamlHoverInfoProvider.java +++ b/vscode-extensions/commons/commons-yaml/src/main/java/org/springframework/ide/vscode/commons/yaml/hover/YamlHoverInfoProvider.java @@ -63,30 +63,32 @@ public class YamlHoverInfoProvider implements HoverInfoProvider { YamlFileAST ast = getAst(doc); if (ast != null) { IRegion region = getHoverRegion(ast, offset); - YamlDocument ymlDoc = new YamlDocument(doc, structureProvider); - YamlAssistContext assistContext = assistContextProvider.getGlobalAssistContext(ymlDoc); - if (assistContext != null) { - List> astPath = ast.findPath(offset); - final YamlPath path = YamlPath.fromASTPath(astPath); - if (path != null) { - YamlPath assistPath = path; - if (assistPath.pointsAtKey()) { - // When a path points at a key we must tramsform it to a - // 'value-terminating path' - // to be able to reuse the 'getHoverInfo' method on - // YamlAssistContext (as navigation - // into 'key' is not defined for YamlAssistContext. - String key = path.getLastSegment().toPropString(); - assistPath = path.dropLast().append(YamlPathSegment.valueAt(key)); - } - assistContext = assistPath.traverse(assistContext); - if (assistContext != null) { - if (path.pointsAtValue()) { - Renderable info = assistContext.getValueHoverInfo(ymlDoc, new DocumentRegion(doc, region)); + if (region!=null) { + YamlDocument ymlDoc = new YamlDocument(doc, structureProvider); + YamlAssistContext assistContext = assistContextProvider.getGlobalAssistContext(ymlDoc); + if (assistContext != null) { + List> astPath = ast.findPath(offset); + final YamlPath path = YamlPath.fromASTPath(astPath); + if (path != null) { + YamlPath assistPath = path; + if (assistPath.pointsAtKey()) { + // When a path points at a key we must tramsform it to a + // 'value-terminating path' + // to be able to reuse the 'getHoverInfo' method on + // YamlAssistContext (as navigation + // into 'key' is not defined for YamlAssistContext. + String key = path.getLastSegment().toPropString(); + assistPath = path.dropLast().append(YamlPathSegment.valueAt(key)); + } + assistContext = assistPath.traverse(assistContext); + if (assistContext != null) { + if (path.pointsAtValue()) { + Renderable info = assistContext.getValueHoverInfo(ymlDoc, new DocumentRegion(doc, region)); + return Tuples.of(info, region); + } + Renderable info = assistContext.getHoverInfo(); return Tuples.of(info, region); } - Renderable info = assistContext.getHoverInfo(); - return Tuples.of(info, region); } } }