From c8554089bc1a05fd61b62783b11a8bad29a09970 Mon Sep 17 00:00:00 2001 From: Martin Lippert Date: Tue, 14 Aug 2018 18:17:10 +0200 Subject: [PATCH] fixed a NPE when the resource of a changed bean is not defined --- .../SpringLiveChangeDetectionWatchdog.java | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringLiveChangeDetectionWatchdog.java b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringLiveChangeDetectionWatchdog.java index 5137a0d70..7314408f3 100644 --- a/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringLiveChangeDetectionWatchdog.java +++ b/headless-services/spring-boot-language-server/src/main/java/org/springframework/ide/vscode/boot/java/utils/SpringLiveChangeDetectionWatchdog.java @@ -230,36 +230,39 @@ public class SpringLiveChangeDetectionWatchdog { String result = null; String resource = liveBean.getResource(); - Pattern BRACKETS = Pattern.compile("\\[[^\\]]*\\]"); + if (resource != null) { - Matcher matcher = BRACKETS.matcher(resource); - if (matcher.find()) { - String type = resource.substring(0, matcher.start()).trim(); - String path = resource.substring(matcher.start()+1, matcher.end()-1); + Pattern BRACKETS = Pattern.compile("\\[[^\\]]*\\]"); - for (IJavaProject project : projects) { - if (SpringResource.FILE.equals(type)) { - String relativePath = SpringResource.projectRelativePath(project, path); + Matcher matcher = BRACKETS.matcher(resource); + if (matcher.find()) { + String type = resource.substring(0, matcher.start()).trim(); + String path = resource.substring(matcher.start()+1, matcher.end()-1); - if (relativePath != path && path.endsWith(SourceLinks.CLASS)) { - result = sourceLinks.sourceLinkUrlForClasspathResource(project, relativePath).get(); - break; - } else { - result = sourceLinks.sourceLinkForResourcePath(Paths.get(path)).get(); + for (IJavaProject project : projects) { + if (SpringResource.FILE.equals(type)) { + String relativePath = SpringResource.projectRelativePath(project, path); + + if (relativePath != path && path.endsWith(SourceLinks.CLASS)) { + result = sourceLinks.sourceLinkUrlForClasspathResource(project, relativePath).get(); + break; + } else { + result = sourceLinks.sourceLinkForResourcePath(Paths.get(path)).get(); + break; + } + } + else if (SpringResource.CLASS_PATH_RESOURCE.equals(type)) { + result = sourceLinks.sourceLinkUrlForClasspathResource(project, path).get(); break; } } - else if (SpringResource.CLASS_PATH_RESOURCE.equals(type)) { - result = sourceLinks.sourceLinkUrlForClasspathResource(project, path).get(); - break; - } } - } - if (result != null) { - int position = result.lastIndexOf('#'); - if (position > 0) { - result = result.substring(0, position); + if (result != null) { + int position = result.lastIndexOf('#'); + if (position > 0) { + result = result.substring(0, position); + } } } return result;