From b0d5da697d3bc1e018ff03eb1780177136e8f4d1 Mon Sep 17 00:00:00 2001 From: Gesa Hentschke <123444711+ghentschke@users.noreply.github.com> Date: Tue, 9 May 2023 15:43:31 +0200 Subject: [PATCH] fix NPE in CProjectChangeMonitor (#52) (#53) fixes #52 --- .../ui/clangd/CProjectChangeMonitor.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/bundles/org.eclipse.cdt.lsp.editor.ui/src/org/eclipse/cdt/lsp/editor/ui/clangd/CProjectChangeMonitor.java b/bundles/org.eclipse.cdt.lsp.editor.ui/src/org/eclipse/cdt/lsp/editor/ui/clangd/CProjectChangeMonitor.java index 8e7935b8..997e15c4 100644 --- a/bundles/org.eclipse.cdt.lsp.editor.ui/src/org/eclipse/cdt/lsp/editor/ui/clangd/CProjectChangeMonitor.java +++ b/bundles/org.eclipse.cdt.lsp.editor.ui/src/org/eclipse/cdt/lsp/editor/ui/clangd/CProjectChangeMonitor.java @@ -42,20 +42,22 @@ public void handleEvent(CProjectDescriptionEvent event) { if (project != null && LspEditorPreferencesTester.preferLspEditor(project)) { ICConfigurationDescription newConfig = newCProjectDecription.getDefaultSettingConfiguration(); var cwdBuilder = newConfig.getBuildSetting().getBuilderCWD(); - try { - var cwdString = CCorePlugin.getDefault().getCdtVariableManager().resolveValue(cwdBuilder.toOSString(), "", null, newConfig); - var projectLocation = project.getLocation().addTrailingSeparator().toOSString(); - var databasePath = cwdString.replace(projectLocation, ""); + if (cwdBuilder != null) { try { - ClangdConfigurationManager.setCompilationDatabase(project, databasePath); - } catch (ScannerException e) { - var status = new Status(IStatus.ERROR, LspEditorUiPlugin.PLUGIN_ID, e.getMessage()); - var configFile = ClangdConfigurationManager.CLANGD_CONFIG_FILE_NAME; - LspUtils.showErrorMessage(LspEditorUiMessages.CProjectChangeMonitor_yaml_scanner_error, - LspEditorUiMessages.CProjectChangeMonitor_yaml_scanner_error_message + projectLocation + configFile , status); + var cwdString = CCorePlugin.getDefault().getCdtVariableManager().resolveValue(cwdBuilder.toOSString(), "", null, newConfig); + var projectLocation = project.getLocation().addTrailingSeparator().toOSString(); + var databasePath = cwdString.replace(projectLocation, ""); + try { + ClangdConfigurationManager.setCompilationDatabase(project, databasePath); + } catch (ScannerException e) { + var status = new Status(IStatus.ERROR, LspEditorUiPlugin.PLUGIN_ID, e.getMessage()); + var configFile = ClangdConfigurationManager.CLANGD_CONFIG_FILE_NAME; + LspUtils.showErrorMessage(LspEditorUiMessages.CProjectChangeMonitor_yaml_scanner_error, + LspEditorUiMessages.CProjectChangeMonitor_yaml_scanner_error_message + projectLocation + configFile , status); + } + } catch (CoreException | IOException e) { + LspEditorUiPlugin.logError(e.getMessage(), e); } - } catch (CoreException | IOException e) { - LspEditorUiPlugin.logError(e.getMessage(), e); } } }